-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 20-Aug-2002/11:28 -0700, Desmond Lee <[EMAIL PROTECTED]> wrote: >What i'm trying to do is automate a virus scan and back up on some of the >folders on my server. I'm really new at this so any help is much >appreciated :) > >First off, to automate a process i have to set it up in the /etc/crontab >correct?
Yes. To schedule a one-time job you should use 'at' instead. >Also, what do i do if i want the info to be sent to someone other that >root when the virus scan and back up run? Set the MAILTO variable in the crontab file: [EMAIL PROTECTED] [snip] >Okay, so i'm pretty sure that the above is correct. However, when i pipe >out the results of the virus scan to a log file, i want to use the date >as the name of the log file. IS there any way that i can do this? It would probably be best to put all the required commands into a script and just call the script using cron. Such a script might look like this: #!/bin/sh # # Scan files for viruses and email a notice of the results. # Who gets notified. [EMAIL PROTECTED] msgsubj='Antivirus Scan Results' # Set the list of directories to scan dirlist='/www/servers/skylight.ubc.ca/media/ /www/servers/skylight.ubc.ca/profsTalk' # Send scan output to this file. reportfile=`date +%Y-%m-%d.txt` # Run the scan and send the result notice. if sun sweep $dirlist > $reportfile; then msgbody="Scan completed successfully. See $reportfile" else msgbody="Scan failed. See $reportfile" fi echo "$msgbody" | mail -s "$msgsubj" $recipient # End of script >Second, the cron tab will run the backup.sh script file. I've just started >to write this script file but i'll a little unsure of what to do. I'm just >writing this out as psuedo code, this is what i've got so far: > ># ># Back up shell script ># > >#!/usr/bin/bash bash is in /bin and this must be the first line of the script. Actually, you should avoid using bash and use sh instead. Your scripts will be more portable: #!/bin/sh >$currDate = getDate; When setting a variable, do not use '$'. That symbol is used to retrieve a variable value. You're trying to set the variable, not retrieve its value. Do not put whitespace around the equals (=) sign when setting a variable. Bash respects end-of-line. You do not have to end your lines with a semi-colon. Perl/C habits die hard, huh? ;-) The command would look like this: currDate=`date +%Y-%m-%d` Today, the $currDate variable would contain "2002-08-20", which is a good format for sorting. >mkdir /data/backups/$currDate > ># Backup the web server files >tar cfv www.tar /data/www >gzip www.tar You can tar and gzip in one step: tar -czvf www.tar.gz /data/www [snip] >Also, I think i have to be root to run the above commands, should this be a >problem, or does the crontab run the backup.sh script as root? In /etc/crontab, you can specify the user that the command should run as. Specifying root is no problem, if that is necessary for the command to function properly. Tony - -- Anthony E. Greene <mailto:[EMAIL PROTECTED]> OpenPGP Key: 0x6C94239D/7B3D BD7D 7D91 1B44 BA26 C484 A42A 60DD 6C94 239D AOL/Yahoo Chat: TonyG05 HomePage: <http://www.pobox.com/~agreene/> Linux: the choice of a GNU Generation. <http://www.linux.org/> -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: Anthony E. Greene 0x6C94239D <[EMAIL PROTECTED]> iD8DBQE9YpxYpCpg3WyUI50RAsL+AJ9gqgP8+7YYXu5pL+A7bPb9osQGyQCg4Rpt V9u7xy8OoHXO9KqtwO7WwZk= =6Wll -----END PGP SIGNATURE----- -- redhat-list mailing list unsubscribe mailto:[EMAIL PROTECTED]?subject=unsubscribe https://listman.redhat.com/mailman/listinfo/redhat-list