How to Save and Manage Cron Jobs Using Nano Editor in Linux


8 views

When you execute crontab -e in your terminal, the system creates a temporary file in /tmp/ directory (as shown in your case: /tmp/crontab.Q1SgwM/crontab). This is where your current crontab entries are loaded for editing.

After entering your cron job:

*/30 * * * * wget -q -O /dev/null http://mywebsite.org/admin/cron.php

To save in nano:

  1. Press Ctrl+O (WriteOut)
  2. Confirm the filename (just press Enter)
  3. Press Ctrl+X to exit nano

To check if your cron job was saved successfully:

crontab -l

This will list all active cron jobs for your user.

To edit existing cron jobs:

crontab -e

The system will open your current crontab in the default editor (nano in your case). The temporary file path will be different each time, but your changes will persist in the system's crontab database.

Once saved:

  • The cron daemon automatically reloads the crontab
  • No manual restart is needed
  • Your job will run at the specified intervals (every 30 minutes in your example)

Here's a more complex crontab example:

# Backup database daily at 2:30 AM
30 2 * * * /usr/bin/mysqldump -u user -ppassword dbname > /backups/db_backup.sql

# Clear temp files every Monday at 3 AM
0 3 * * 1 rm -rf /tmp/*

# Your existing job
*/30 * * * * wget -q -O /dev/null http://mywebsite.org/admin/cron.php
  • Check cron logs: grep CRON /var/log/syslog
  • Test commands directly in shell before adding to crontab
  • Use full paths to binaries in cron jobs
  • Redirect output to debug: > /path/to/logfile 2>&1

When working with cron jobs on Linux servers through SSH clients like Putty, the crontab -e command opens the user's cron table in the default editor (often nano or vi). The temporary file path shown (e.g., /tmp/crontab.Q1SgwM/crontab) is normal - this is where the system stores the file during editing.

After adding your cron entry (like the example below), follow these steps:

# m h dom mon dow command
*/30 * * * * wget -q -O /dev/null http://mywebsite.org/admin/cron.php

To save in nano:

  1. Press Ctrl+O (WriteOut)
  2. Confirm the filename by pressing Enter
  3. Press Ctrl+X to exit

To view your active cron jobs:

crontab -l

To edit again later, simply run:

crontab -e

The cron daemon automatically reloads jobs when you save through crontab -e. No additional steps are needed for activation. The job will run according to its schedule (every 30 minutes in the example).

Here's a more complete example for WordPress maintenance:

# Clean up expired transients every 6 hours
0 */6 * * * cd /var/www/html && wp transient delete --expired --quiet

# Run scheduled posts hourly
5 * * * * wget -q -O /dev/null https://yoursite.com/wp-cron.php
  • Check cron logs: grep CRON /var/log/syslog
  • Test commands directly in shell before adding to cron
  • Consider adding MAILTO at the top of your crontab for error notifications