How to Connect to Your VDS Server via SSH (Complete Guide)
Step-by-step SSH connection guide for Linux VDS: PuTTY, Terminal, key-based authentication, Path Panel firewall rules, and security best practices.
Create and manage scheduled tasks on Linux with crontab: cron expression syntax, practical examples, logging output, and avoiding common pitfalls.
Cron is a time-based job scheduler in Linux that automatically runs commands and scripts at specified times or intervals. It is essential for automating repetitive tasks like backups, log cleanup, and update checks.
The cron service is installed and running by default on most Linux distributions. Check its status with systemctl status cron or systemctl status crond.
Each cron job consists of five time fields and the command to run:
* * * * * /path/to/command
│ │ │ │ │
│ │ │ │ └── Day of week (0-7, 0 and 7 = Sunday)
│ │ │ └──── Month (1-12)
│ │ └────── Day of month (1-31)
│ └──────── Hour (0-23)
└────────── Minute (0-59)
| Character | Meaning | Example |
|---|---|---|
* | Any value | * * * * * = every minute |
, | Multiple values | 1,15 * * * * = at minute 1 and 15 |
- | Range | 1-5 * * * * = minutes 1 through 5 |
/ | Step | */5 * * * * = every 5 minutes |
# Run every minute
* * * * * /usr/bin/script.sh
# Run at the top of every hour
0 * * * * /usr/bin/script.sh
# Run every day at 02:30
30 2 * * * /usr/bin/backup.sh
# Run every Monday at 08:00
0 8 * * 1 /usr/bin/weekly-report.sh
# Run on the 1st of every month at midnight
0 0 1 * * /usr/bin/monthly-cleanup.sh
# Run every 5 minutes
*/5 * * * * /usr/bin/check-service.sh
# Run on weekdays (Mon-Fri) at 09:00
0 9 * * 1-5 /usr/bin/workday-task.sh
# Run every 6 hours
0 */6 * * * /usr/bin/sync.sh
@reboot # Once at system startup
@yearly # Once a year (0 0 1 1 *)
@monthly # Once a month (0 0 1 * *)
@weekly # Once a week (0 0 * * 0)
@daily # Once a day (0 0 * * *)
@hourly # Once an hour (0 * * * *)
# Edit the current user's crontab
crontab -e
# Edit a specific user's crontab (requires root)
crontab -u username -e
# List current crontab
crontab -l
# Remove crontab (use with caution!)
crontab -r
The crontab -r command deletes all your cron jobs and cannot be undone. Back up first with crontab -l > crontab_backup.txt.
# Run crontab -e
crontab -e
# If prompted to choose an editor, select nano (option 1)
# Add your job at the end of the file:
30 2 * * * /home/user/backup.sh
# Save and exit: Ctrl+X, Y, Enter (for nano)
System-wide cron jobs use the /etc/cron* directories:
# Directory structure
/etc/crontab # Main system crontab file
/etc/cron.d/ # Application cron files
/etc/cron.hourly/ # Scripts run hourly
/etc/cron.daily/ # Scripts run daily
/etc/cron.weekly/ # Scripts run weekly
/etc/cron.monthly/ # Scripts run monthly
# /etc/crontab format (includes user field)
30 2 * * * root /usr/bin/backup.sh
# Cron logs on Debian/Ubuntu
sudo tail -f /var/log/syslog | grep CRON
# On RHEL/CentOS
sudo tail -f /var/log/cron
# With journald
sudo journalctl -u cron -f
sudo journalctl -u crond -f
# Redirect both stdout and stderr to a file
30 2 * * * /usr/bin/backup.sh >> /var/log/backup.log 2>&1
# Log only errors
30 2 * * * /usr/bin/backup.sh 2>> /var/log/backup-errors.log
# Suppress all output
30 2 * * * /usr/bin/backup.sh > /dev/null 2>&1
Configure logrotate to rotate log files so they don't grow indefinitely.
Cron does not inherit the user shell's environment variables. Define PATH and other variables explicitly:
# Add to the top of your crontab
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
SHELL=/bin/bash
# Or use full paths in commands
30 2 * * * /usr/bin/python3 /home/user/script.py
# Grant execute permission to the script
chmod +x /home/user/backup.sh
# Verify permissions
ls -la /home/user/backup.sh
# Explicitly set the working directory in the cron job
30 2 * * * cd /var/www/html && php artisan schedule:run
# Or use bash -c
30 2 * * * /bin/bash -c 'cd /var/www/html && php artisan schedule:run'
# Check if cron is running
sudo systemctl status cron # Debian/Ubuntu
sudo systemctl status crond # RHEL/CentOS
# Restart the service
sudo systemctl restart cron
# Test the script manually first
bash /home/user/backup.sh
# Simulate the cron environment
env -i HOME=/root SHELL=/bin/bash PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin /home/user/backup.sh
# Redirect cron output to a file instead of email
MAILTO=""
30 2 * * * /home/user/backup.sh >> /tmp/cron-test.log 2>&1
Cron is one of the fundamental tools in Linux system administration. With correct syntax, environment variable management, and logging, you can build reliable automation. Regularly review your jobs with crontab -l and monitor log files to catch issues early.
The most common causes are: the script lacks execute permission (chmod +x), the PATH environment variable is not defined (cron runs in a restricted environment), the script uses relative paths instead of absolute paths, or the cron service is not running. Check /var/log/syslog or /var/log/cron for error messages.
Redirect the job's output to a log file: '30 2 * * * /script.sh >> /var/log/script.log 2>&1'. Then monitor it with 'tail -f /var/log/script.log'. You can also check cron logs with 'sudo grep CRON /var/log/syslog'.
Use the @reboot shortcut: '@reboot /home/user/startup.sh'. This runs the command every time the server starts. Creating a systemd service is also a more reliable alternative.
Add 'MAILTO=""' at the top of your crontab file. Or append '> /dev/null 2>&1' to each job to suppress all output.
Step-by-step SSH connection guide for Linux VDS: PuTTY, Terminal, key-based authentication, Path Panel firewall rules, and security best practices.
Complete guide to connecting to Windows Server VDS via Remote Desktop (RDP): setup steps, NLA security, Path Panel firewall rule, and troubleshooting tips.
Step-by-step guide to changing your VDS server OS via REXE panel: backup tips, supported Linux distributions and Windows Server versions explained.