ShellSpells
  • 🧙‍♂️Welcome!
    • ShellSpells
    • FAQs
    • License & Disclaimer
  • 🐧Linux
    • System Ops
      • Transcripts
      • Help
      • System Info
        • Date/Time
        • System Details
        • Patches & Updates
        • Init System Identification
        • Hostname / Host ID
        • Variables
        • Hardware & Resources
      • Filesystem
        • Traverse & Enumerate
        • Drives & Partitions
        • Shares
        • Packages
        • Connected Devices
        • Kernel Modules (Drivers)
      • Users & Groups
        • Enumerate
        • Modify
      • Network
        • Enumerate
        • Modify
      • Scheduled Jobs
        • Enumerate
        • Modify
      • Processes
        • Enumerate
        • Modify
        • Custom Script and Shared Object
        • Process I/O Redirection
      • Services
        • Enumerate
        • Modify
        • Create a Service
      • Startup/Boot Scripts
        • Enumerate
        • Modify
      • Security
        • Antivirus
        • Firewall
        • SSH Keys
      • History & Logs
        • History
        • Logs
    • File Ops
      • Search
        • Filename
        • Content
        • Users (Owners)
        • Time
        • Size
        • Permission
        • Hidden Files
        • Inode
        • Find + Exec
        • Notes
      • Enumerate Metadata
      • Modify Metadata
      • Read Content
      • Modify Content
      • Extract Content
      • Sort / Compare / Count
      • Move
      • Copy
      • Execute
      • Hash
      • Encode/Decode
      • Compress/Decompress
      • Working With Weird Filenames
    • Terminal Ops
      • Keyboard Shortcuts
      • Tmux Shortcuts
  • 🪟Windows
    • System Ops
      • Transcripts
      • Help
      • System Info
        • One-liners
        • Date/Time
        • System Details
        • Hotfixes
        • Domain or Workgroup
        • Data Execution Prevention
        • Variables
        • Hardware & Resources
      • Filesystem
        • Traverse & Enumerate
        • Drives & Partitions
        • Installed Software
        • Drivers
        • Shares
      • Registry
        • Enumerate
        • Modify
        • Forensically Relevant Keys
      • Users & Groups
        • Enumerate
        • Modify
      • Network
        • Enumerate
        • Modify
      • Scheduled Tasks
      • Processes
        • Enumerate
        • Modify
      • Services
        • Enumerate
        • Modify
      • Autorun / Startup
        • Enumerate
        • Modify
      • Security
        • Permissions
          • Enumerate
          • Page
        • Antivirus
        • Firewall
          • Enumerate
          • Modify
        • Audit Policies
        • Remoting
          • Enumerate
          • Modify
          • Registry Locations
        • Stored Credentials
      • Remote Command Execution
      • Active Directory
        • Enumerate
        • Modify
      • History & Logs
        • History
        • Logs
      • PowerShell Config
      • Scripting
      • WMIC Notes
    • File Ops
      • Search
        • Filename
        • Time
        • Size
        • Permissions
        • Attributes
        • Wildcarding
      • Enumerate Metadata
        • One Liners
        • Users (Owners)
        • Timestamps
        • Size
        • Permissions
        • Attributes
      • Modify Metadata
        • Change Owner
        • Timestamps
        • Size
        • Attributes
      • Read Content
      • Modify Content
        • Overwrite
        • Insert
        • Append
        • Replace / Remove
        • Convert Case
        • Alternate Data Streams
      • Extract Content
      • Sort / Compare / Count
        • Sort
        • Count
        • Compare
      • Move
      • Copy
      • Execute
      • Hash
      • Encode/Decode
      • Compress/Decompress
      • Working With Weird Filenames
      • Output Formatting / Filtering
      • File Formatting
      • Operators
  • ⛓️Network
    • Traffic Manipulation
      • iptables
        • Option List
        • General Commands
        • Filter Tables
        • NAT
        • Mangle
        • Filter for SSH Traffic (Example)
      • nftables
    • Packet Capture
      • Syntax
      • TCPDump Examples
    • Packet Analysis
      • Wireshark
  • 🚗Maneuver
    • SSH
    • Control Sockets
    • RDP
    • Windows Port Proxy
  • 🛩️Data Transfer
    • SCP
    • FTP
    • Netcat
      • Netcat Relays
    • Server Interactions
    • Alternate Methods
  • 🪄REGEX
    • Examples
Powered by GitBook
On this page
  • Cron Jobs
  • Modifying Existing Tasks
  • Deleting Tasks
  • Systemd Timers
  • Example Workflow
  • Creating a Service Unit
  • Creating New Timer Unit
  • Managing Systemd Timers
  • Inspecting Timers
  • Anacron
  • Modifying Anacrontab Jobs
  • Creating Anacron Jobs
  • Forcing Task Execution:
  • at
  • Creating at Jobs
  • Other Tools

Was this helpful?

  1. Linux
  2. System Ops
  3. Scheduled Jobs

Modify

Cron Jobs

Modifying Existing Tasks

crontab -e

Opens the current user's crontab for editing.

crontab -e -u <username>

Opens another user's crontab for editing (requires root privileges).

Deleting Tasks

crontab -l

Lists all crontab entries.

crontab -r

Removes all entries from the current user's crontab.

crontab -r -u <username>

Removes all entries from another user's crontab (requires root privileges).

Edit the crontab file to comment out or remove specific lines.

Examples: Run a script every hour: 0 * * * * /path/to/script.sh Backup files daily at midnight: 0 0 * * * tar -czf /path/to/backup.tar.gz /path/to/files Send an email weekly on Sundays: 0 0 * * 0 mail -s "Weekly Report" user@example.com < /path/to/report.txt Run a backup script at 3 am every day: 0 3 * * * /path/to/backup_script.sh

* * * * * command to execute
- - - - -
| | | | |
| | | | +------------ Day of the week (0 - 7) (Sunday=0 or 7)
| | | +------------ Month (1 - 12)
| | +------------ Day of the month (1 - 31)
| +------------ Hour (0 - 23)
+------------ Minute (0 - 59)

Systemd Timers

Example Workflow

Create the service unit that specifies what command or script to run. Create the timer unit that specifies when the service should be triggered. Start and enable the timer to ensure it runs as scheduled. Inspect the timer as needed to verify its configuration and status. <==

Creating a Service Unit

Create a .service file in /etc/systemd/system/ for your task. For example, mytask.service:

[Unit]
Description=Example systemd service.

[Service]
Type=simple
ExecStart=/path/to/your/script.sh

Creating New Timer Unit

systemctl edit <timer_name>.timer

Opens the new timer unit file for editing in your default text editor.

systemd-run --on-active=<time> [command]

Creates a transient timer that executes a command after a specified time (e.g., systemd-run --on-active=30 /bin/touch /tmp/foo).

systemd-analyze timers

Analyzes and reports information about existing timers, helping you understand the system's current timer configuration.

Create a corresponding .timer file in the same directory. For example, mytask.timer:

[Unit]
Description=Timer for mytask

[Timer]
OnBootSec=15min
OnUnitActiveSec=24h
Unit=mytask.service

[Install]
WantedBy=timers.target

Managing Systemd Timers

Editing an existing timer:

systemctl edit <timer_name>.timer

Opens the existing timer unit file for editing in your default text editor.

systemctl reload

Reloads systemd after editing the timer unit file to apply changes.

Enabling/Disabling Timers:

systemctl enable <timer_name>

Enables a timer to start automatically at its scheduled time.

systemctl disable <timer_name>

Disables a timer from starting automatically.

Manually Start/Stop:

systemctl start <timer_name>

Starts a timer manually.

systemctl stop <timer_name>

Stops a timer manually.

Inspecting Timers

systemctl list-timers

Lists all active timers along with their next scheduled execution time.

systemctl status mytask.timer

Shows the status of the specified timer, including whether it's active and when it last triggered the service.

systemctl cat mytask.timer

Displays the content of the timer unit file.

systemctl cat mytask.service

Displays the content of the service unit file.

Anacron

Modifying Anacrontab Jobs

crontab -e

Opens the user's Anacrontab for editing.

ls -l /var/spool/anacron

User anacron jobs are here.

ls -l /etc/anacrontab

ain anacron configuration file

Edit the entries like a standard crontab, but use specific Anacron time specifiers (e.g., "daily", "10d").

Example: sudo vim /etc/anacrontab add the following to create a new anacron job that runs a script daily, even if the system is not always on: 1 5 my_daily_script /path/to/script.sh [period] [delay] [job-identifier] [command]

period

How often the job should run, in days.

delay

Delay in minutes before starting the job after anacron starts.

job-identifier

A unique name for the job's log file.

command

The command or script to be executed.

Creating Anacron Jobs

Example: Run a script every 3 hours with a random delay of 60 minutes: 360 * /path/to/script.sh

Forcing Task Execution:

anacron -f

Runs all scheduled tasks immediately, regardless of their scheduled times.

sudo anacron -f -d <job_name>

Force the execution of a specific Anacron job manually with debug output.

sudo anacron -n

Runs all jobs in the Anacrontab as if anacron had just been started, respecting the delay specified for each job.

at

atrm <job_id>

Removes a specific job from the queue.

atq

View and manipulate tasks scheduled with the at command.

Creating at Jobs

at <time>

Schedules a job to run at a specific time (e.g., at 10:30AM).

at +<duration>

Schedules a job to run after a specific duration (e.g., at +30 minutes).

at now + 2 hours

Schedules a one-time job to run at a specific time (e.g., 2 hours from now).

Examples: at 10:30AM < /path/to/script.sh

Other Tools

Command
Description

batch

Modifies jobs submitted with the batch command (if available).

PreviousEnumerateNextProcesses

Last updated 1 year ago

Was this helpful?

🐧