Quote:
I am new to crontab & solaris sytem,I have to schedule a text file on Solaris system by using crontab command so that shell script which is inside that text file will run at specific time.
|
Watch out with your terminology. Text files and shell scripts, while both are, technically "text" files (in that they don't contain text formatting commands or control sequences like a word processor would insert), they mean different things to most UNIX users. Shell scripts contain commands that you need/want to run, probably repeatedly or you wouldn't have gone to the trouble of putting them in a file. "Text" files usually mean a plain file that you've edited and contains, well, plain ol' text (phone numbers, comments about a project, etc.).
Quote:
I have deleted the previous crontab file in var/spool/cron/crontab. by using crontab -r.
|
As others have already mentioned, this was probably a mistake. Let's hope you have a backup from which you can restore that file. If not, and it's a newly installed system, you likely didn't have any customizations that haven't been backed up somewhere and you may be able to copy the basic root crontab entries from another system using "crontab -l > crontab.root" and copying that file to your system.
Then... use that file to restore the actual crontab entries using "crontab ./crontab.root". If you do not have access to another Solaris system, here's what the root crontab contains on my fairly plain vanilla Solaris 10 system:
Code:
#
# The root crontab should be used to perform accounting data collection.
#
#
10 3 * * * /usr/sbin/logadm
15 3 * * 0 /usr/lib/fs/nfs/nfsfind
30 3 * * * [ -x /usr/lib/gss/gsscred_clean ] && /usr/lib/gss/gsscred_clean
#10 3 * * * /usr/lib/krb5/kprop_script ___slave_kdcs___
Note: I wouldn't use these on any other version of Solaris as I have no idea whether the commands are applicable for any version other than Sol10.
If you clobbered the crontab entries for a
different account, you're going to have to access a recent backup ro restore /var/spool/cron/crontabs/username. Or figure out how to apologize to a disgruntled user.
Quote:
Can anyone let me know the things step by step like how to create & what are the commands we need to use while scheduling through crontab in the Unix environment(Putty).
|
Well, "crontab -l" and "crontab
path-to-file-containing-cron-entries" have served me well over the years. Say... since you're new to cron, one thing that bites a lot of cron users is that the script must define all the shell environment settings that you'll need when the script runs. If your script has been running when you execute from the command line it may have been relying on shell variable settings that are defined in your .profile/.bashrc/whatever file sourced when you login. If that's the case, your script will almost certainly fail or will run in an unexpected way when you run it via cron; cron doesn't run through your .profile when it executes the command you've defined.
Finally... While the crontab man page says you can modify the cron entries directly using "crontab -e", I much prefer to edit the file ("crontab.root" in my example) and update the crontab entries with that "crontab ./crontab.root" command. Modifying the crontab entries directly doesn't give you any backup capability. If you're making frequent changes to the cron jobs and you need to back out changes, you might consider a.) making copies of your local crontab file (like "cp crontab.root crontab.root.20120727") before altering the contents and resubmitting or b.) using RCS to retain a history of your changes to the crontab file in your home directory. (You could then check the file out and back into RCS as needed after you've made changes. If you screw something up it's quite easy to retrieve a known-to-be-working copy of the crontab entries from RCS and resubmitting them. Probably something best left to a later discussion as I suspect I'm getting just a little off-topic.
)