cron a script

This has to be the ultimate newbie question...

I have a script that works well. To run it, I cut and paste it into a putty session.

Is there a way to put the script into a file and just run that file -- like a DOS batch file?

I'd like to schedule the file to run daily.

Thanks,
-dog

  1. open a file in an editor: script.sh
  2. place your commands there.
    if you are going to run it in cron (scheduler) put these lines at the top of the file
#!/bin/bash                       <- forces the script to use bash otherwise you get /bin/sh whatever that is.
. /etc/profile
. /path/to/dog/home/.profile                            <- if you do not have .profile, skip it
close the file.
chmod \+x /path/to/my/script.sh   &lt;- makes the script executable.
  1. crontab -e lets you enter a job for scheduling. Here is a cron tutorial:
    Crontab � Quick Reference
5 23 1 * * /path/to/script.sh 

will run the script at 11:05 every month on day one of the month, for example.

1 Like

Hi

Just cut and paste the script into a new file using vi or any other editor.

For example my_script

Then change the right so you can execute this file :

$ chmod +x my_file

And now you can run the script

$ ./my_script

To finish you have at least two choice to run this script daily.

  1. Copy the script file to /etc/cron.daily (if you have the right to do it)
  2. Launch : crontab -e to add a line like this
30 14 * * * /home/mylogin/myscript

This will launch the script everyday at 14:30

Edit: jim mcnamara was faster :slight_smile:

1 Like

Chirel, Jim - Thank you!