Computing.Net > Forums > Linux > cron script

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

cron script

Reply to Message Icon

Name: john
Date: December 29, 2002 at 11:00:29 Pacific
OS: red hat 7.2
CPU/Ram: pentium II 500MB RAM
Comment:

Hello to everyone in the group. I am a beginner with linux but have enjoyed adding this red hat box to my home network. So far I have a router and file sharing set up. I'm looking for a sample Cron script ( I think ) I want to set up a nightly backup for my windows laptop. If someone can point me in the right direction I'm much obliged.

regards and thanks

John



Sponsored Link
Ads by Google

Response Number 1
Name: David Perry
Date: December 29, 2002 at 11:49:50 Pacific
Reply:

Does you unix machine have the samba client installed? Does smbtar do what you need it to

if you have a scsi tape drive as /dev/st0

you can use tar to back up a directory

tar cvf /dev/st0 /directoryname

smbtar allows you to do something similar with windows shares. Once you get the commands like you like them, write them to a file. Have cron execute this script you just wrote whenever you like

#----------8<--------cut here-------8<-------
#!/bin/sh
# sample smbtar.sh
# let's save this in /usr/local/bin/smbtar.sh
SERVER=windows_server_name
USER=username
PASSWD=password
TAPE=/dev/st0
/usr/bin/smbtar -s $SERVER -u $USER -p $PASSWD -t $TAPE
#----------8<--------cut here-------8<-------

then add the line to your cron file

0 4 * * * /usr/local/bin/smbtar.sh

this will execute the script daily at 4:00 a.m. Make the script executable

chmod ugo+x /usr/local/bin/smbtar.sh

reference the online docs for smbtar for more information

man smbtar


0

Response Number 2
Name: John
Date: December 29, 2002 at 14:12:43 Pacific
Reply:

Yes I do have samba installed and I can read all the correct directories. This looks like it will work fine. One question, does the cron script, smbtar.sh in the example above, have to be in a certain directory to be 'executed' at 4:00 am everyday? What exactly 'fires' it off everyday? Is it the fact that it has a .sh extension? I would like to understand this.

thanks again

jOhn


0

Response Number 3
Name: David Perry
Date: December 29, 2002 at 15:45:35 Pacific
Reply:

Unix does not look at the name to determine if a program or script can be executed. The command:

chmod ugo+x /usr/local/bin/smbtar.sh

would give execute priviledges (+x) to user (u), group (g) and other (o) so even someone that didn't own that file could execute it.

You might also see it written

chmod 755 /usr/local/bin/smbtar.sh

I just choose to end scripts with '.sh' so I can tell by looking it is a shell script and not a compiled binary.

The very first line '#!/bin/sh' tells the system to use the shell '/bin/sh' as the interpreter for this script. The same convention applies to perl scripts.

A program does not need to be in a certain directory, however if it is in a directory that is listed in your path, you would only need to type the script name and not the whole path to execute it. It is an accepted convention to store non-system executables in /usr/local/bin although nothing mandates it.

The system has a job that looks at each crontab file every minute to determine if any time based jobs need to be run. Having that entry in your crontab file ( should be in /var/spool/cron/crontabs/yourusername ) is enough to have it run automatically. You can edit your crontab file by typing

crontab -e

man crontab

will tell you more about what you can do with job scheduling.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Linux Forum Home


Sponsored links

Ads by Google


Results for: cron script

BACKUP script (with tar to tape) in CRON www.computing.net/answers/linux/backup-script-with-tar-to-tape-in-cron/12285.html

cron jobs for sending logfiles www.computing.net/answers/linux/cron-jobs-for-sending-logfiles/18914.html

Linux/Windows DSL Sharing www.computing.net/answers/linux/linuxwindows-dsl-sharing/2637.html