LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris
User Name
Password
Solaris / OpenSolaris This forum is for the discussion of Solaris, OpenSolaris, OpenIndiana, and illumos.
General Sun, SunOS and Sparc related questions also go here. Any Solaris fork or distribution is welcome.

Notices


Reply
  Search this Thread
Old 07-20-2012, 06:59 AM   #1
ashish_t51
LQ Newbie
 
Registered: Jul 2012
Posts: 1

Rep: Reputation: Disabled
Need Help On Crontab in Solaris system


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.

I have deleted the previous crontab file in var/spool/cron/crontab.
by using crontab -r.

Now I want to create a fresh copy for crontab file.

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).

thanks in advance.

Last edited by ashish_t51; 07-20-2012 at 07:01 AM.
 
Old 07-20-2012, 10:04 AM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Why did you clear the existing crontab ?

Is this root's one ?
 
Old 07-20-2012, 10:26 AM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,753

Rep: Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983
Quote:
Originally Posted by ashish_t51 View Post
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.
You cannot run a text file. You can run a shell script or other program though.
Quote:
I have deleted the previous crontab file in var/spool/cron/crontab. by using crontab -r.
Why would you DELETE the entire crontab? Did you know what was in there?? If not, you have just deleted EVERYTHING that is supposed to run automatically. I'd strongly suggest restoring that file from backup
Quote:
Now I want to create a fresh copy for crontab file. 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).
Not to sound nasty, but if you need step-by-step guidance on setting up a cron job, should you really be modifying system events like this? You can type in "man crontab", or look on Google for instructions:
http://www.pantz.org/software/cron/croninfo.html
 
Old 07-27-2012, 03:59 PM   #4
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,818

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
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. )
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] can't open crontab on Solaris sam_nyc Linux - Newbie 1 04-10-2012 05:10 PM
Crontab not editing in solaris 8. crown_bd Solaris / OpenSolaris 6 09-06-2007 01:23 AM
crontab disabled after edit on solaris 5.x machines BlackHatRob Solaris / OpenSolaris 1 01-18-2007 09:13 AM
system-wide crontab in /etc/crontab ner Linux - General 2 11-18-2003 12:35 PM

LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris

All times are GMT -5. The time now is 11:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration