![]() ![]() Don't run your cron jobs as root unless they absolutely must have root access, it's better to run things as special users that only has limited permissions in the file system. In many cases it makes sense to run cron jobs as a special user. It’ll open the configuration file in the default text editor on your server. To set up a new command on cron, run crontab -e. Simple debugging writing messages to some file in /tmp/ is also often a way to get your cron jobs running. Cron is another CLI available on Linux that allows us to configure commands to be executed periodically at fixed times, dates or intervals. Any output from cron is sent via mail to the user running the cron job, which is helpful for debugging. This often causes cron jobs to fail the first few times you run them (See my law on cron jobs: :-)). Remember that the environment variables you have available in your shell are not the same as those available when the cronjob runs, so PATH, etc, may be different. If this script is called /opt/scripts/myscript.sh, and is to be run once every 10 minutes, add the following to your crontab (run crontab -e to edit your crontab): That's good for security, and if you want to, you can even limit the receiving side to only allow that ssh key to run rsync's server side. tail /var/log/syslog grep CRON You will likely require root/sudo privileges to access your Syslog. This will just open the file and append to the end of it. On Ubuntu, Debian and related distributions, you will find cron jobs logs in /var/log/syslog Your Syslog contains entries from many operating system components and it's helpful to grep to isolate cron-specific messages. I would use rsync and passwordless authentication via ssh keys. I am not sure if this will solve your problem, but you dont need the filegetcontents(). ![]() In your case, you probably want to write a shell script that use rsync, scp or ftp to transfer the files, make sure that exits successfully (check exit code from transfer, stored in the $? variable), then move the set of files into the original folder. Cron is really simple, all it's doing is to run a command of your choice at the specified times of day.
0 Comments
Leave a Reply. |