π°οΈ Linux/Unix: Scheduling, Logging & Monitoring β Automate, Audit & Analyze Systems Effectively
π§² Introduction β Take Control of Linux System Time, Logs & Performance
In production-grade systems, managing automated jobs, keeping track of system events, and analyzing resource usage are critical for reliability. Linux offers powerful built-in tools for scheduling tasks (cron, at), inspecting logs (journalctl, /var/log), and monitoring system performance (top, vmstat, iostat, sar, dstat).
π― In this guide, youβll learn:
- How to schedule and manage background jobs with
cron,at, andbatch - How to view logs and system messages using
journalctl,logger, and log files - How to monitor CPU, memory, I/O, and network usage for system tuning
π Topics Covered
| π΅ Category | π Description |
|---|---|
| Job Scheduling | Automate repetitive or one-time tasks using cron or at |
| Logging | Track system logs via journal, logger command, and /var/log files |
| System Performance Monitoring | Real-time and historical system metrics using top, vmstat, sar etc. |
π΅ Linux/Unix: Job Scheduling (cron, crontab, at, batch)
πΉ cron β Periodic Task Scheduler
crontab -e
β Edit your personal cron jobs. Each line follows this syntax:
* * * * * /path/to/script.sh
β β β β β
β β β β βββ Day of Week (0-6, Sunday=0)
β β β βββββ Month (1-12)
β β βββββββ Day of Month (1-31)
β βββββββββ Hour (0-23)
βββββββββββ Minute (0-59)
πΉ at β One-Time Job Scheduler
at 5pm
at> echo "Backup Started" >> ~/log.txt
CTRL+D
β Executes the job at the specified time once.
πΉ batch β Queue Jobs When Load is Low
echo "tar czf backup.tar.gz /home/user" | batch
πΉ View & Manage Scheduled Jobs
crontab -l # List cron jobs
atq # View at jobs
atrm <job_number> # Remove at job
π΅ Linux/Unix: Logging (journalctl, logger, /var/log/)
πΉ journalctl β View systemd logs
journalctl -xe
journalctl -u nginx.service
β View system boot logs, service-specific logs, or real-time messages.
πΉ logger β Send messages to system log
logger "Disk space critically low"
β Custom logs written to syslog or journal.
πΉ Log Files in /var/log/
| π Log File | π Description |
|---|---|
/var/log/syslog | General system activity (Debian) |
/var/log/messages | General system messages (RHEL/CentOS) |
/var/log/auth.log | Authentication attempts |
/var/log/kern.log | Kernel logs |
/var/log/dmesg | Boot-time hardware messages |
π΅ Linux/Unix: System Performance (top, vmstat, iostat, sar, dstat)
πΉ top β Real-Time Process Monitor
top
β Monitor CPU, memory, and process usage live.
πΉ vmstat β Virtual Memory Stats
vmstat 2 5
β Memory, swap, IO, and CPU breakdown over 5 intervals.
πΉ iostat β Disk I/O Stats
iostat -xz 1 3
β Check disk throughput and performance metrics.
πΉ sar β Historical Performance Reports
sar -u 1 5 # CPU usage
sar -r 1 5 # Memory usage
β
sysstat package required.
πΉ dstat β Versatile System Stats Tool
dstat -cdngyt --top-cpu
β Great for observing CPU, disk, net, memory, and more.
π Summary β Recap & Next Steps
Whether you’re running a server or managing a workstation, Linux’s native tools give you complete control over scheduling, logging, and performance analysis. Automating your tasks, auditing logs, and watching system health ensures uptime, security, and optimization.
π Key Takeaways:
- Use
crontabfor periodic automation;atfor one-time jobs - View logs via
journalctl,logger, and/var/log/ - Monitor system health using
top,vmstat,iostat, andsar
βοΈ Real-World Applications:
- Automate backups or script runs with cron
- Debug issues by analyzing
/var/logor system journal - Identify bottlenecks in server CPU, RAM, or I/O usage
β Frequently Asked Questions
β How do I stop a cron job from running?
β
Use crontab -e to remove the specific entry, or comment it out with #.
β Whatβs the difference between cron and at?
β
cron runs jobs repeatedly based on schedule; at runs jobs once at a future time.
β Where are Linux logs stored?
β
Common log files reside in /var/log/, while systemd-based systems also use journalctl.
β How do I analyze high CPU usage?
β
Use top, htop, or dstat --top-cpu to find resource-heavy processes.
β Is it safe to delete log files in /var/log/?
β
You can delete old logs, but do it with caution. Use logrotate for safe rotation.
Share Now :
