- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- crontab on solaris
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2006 06:44 PM
тАО05-21-2006 06:44 PM
I have problem when executing script...from command line it works perfect but when I add it to cron it starts going crasy..I know that it might be connecteed with my path variable but how can I fix that so that my script works same like from command line ./myscript
Thanks..:)
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2006 07:02 PM
тАО05-21-2006 07:02 PM
Re: crontab on solaris
When you run a script manually it goes back to environment initialisation. When you run the same script through Cron, it does not run profile therefore you have to initialise the variables in the script or specify the full path.
IA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2006 07:22 PM
тАО05-21-2006 07:22 PM
Re: crontab on solaris
Hi,
cron invokes the command from the user's HOME directory with the shell, (/usr/bin/sh).
cron supplies a default environment for every shell, defining:
HOME=user's-home-directory
LOGNAME=user's-login-id
PATH=/usr/bin:/usr/sbin:.
SHELL=/usr/bin/sh
Please make sure the ENV is set properly. That could be main suspect.
Regards,
Siva.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2006 07:22 PM
тАО05-21-2006 07:22 PM
Re: crontab on solaris
In crontab u have to specify the fullpath of the command which need to execute..
Cheers
Arunkumar.B
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2006 07:33 PM
тАО05-21-2006 07:33 PM
Re: crontab on solaris
I am new in shell scripting..and I have been reading about cron..but I am not sure what should I do I am root user...with my env:
PWD=/var/adm
TZ=MET
_INIT_RUN_NPREV=0
HZ=100
HOSTNAME=xxdmpp
_INIT_RUN_LEVEL=3
LD_LIBRARY_PATH=/opt/SMAW/lib
_INIT_UTS_ISA=sparc
_INIT_UTS_SYSNAME=SunOS
_INIT_UTS_RELEASE=5.8
MANPATH=/usr/share/man:/opt/SMAW/man
_INIT_PREV_LEVEL=S
MACHTYPE=sparc-sun-solaris
MAIL=/var/mail/root
_INIT_UTS_VERSION=Generic_117350-05
JAVA_HOME=/opt/SMAW/SMAWjdk/1.2/
TELEESC=~
TELEROOT=/opt/SMAW/SMAWtssv/tele
LOGNAME=root
_INIT_UTS_NODENAME=xxdmpp
_INIT_UTS_PLATFORM=FJSV,GPUZC-M
SHLVL=1
_INIT_UTS_MACHINE=sun4us
SHELL=/bin/bash
HOSTTYPE=sparc
OSTYPE=solaris
HOME=/
TERM=vt100
PATH=/usr/sbin:/usr/bin:/opt/SMAW/bin:/opt/SMAW/sbin:/opt/SMAW/SMAWtssv/tele/bin
TELETAG=TELE
_INIT_NET_STRATEGY=none
_=/usr/bin/env
OLDPWD=/var/adm/log
and I user root crontab but my machine goes crasy basicly script does not work on good way..on a way it works from command line..
script is written in #!/bin/bash
Please give me a hint..
Cheers,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2006 07:33 PM
тАО05-21-2006 07:33 PM
Re: crontab on solaris
Also use script with the obsolute PATH,
30 18 * * *
Regards,
Siva,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2006 07:35 PM
тАО05-21-2006 07:35 PM
Re: crontab on solaris
Can u pls attach the crontab entry which u made ..
Cheers
Arunkumar.B
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2006 07:43 PM
тАО05-21-2006 07:43 PM
Re: crontab on solaris
* 9,10,11 * * * /opt/tomcat/logs/do/myscript
and I put othing else in cron..this is cron from root..
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2006 09:24 PM
тАО05-21-2006 09:24 PM
Re: crontab on solaris
thanks in advance..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2006 10:17 PM
тАО05-21-2006 10:17 PM
Re: crontab on solaris
I am not sure what the script does.
But I have few suggestion
1. * 9,10,11 * * * /opt/tomcat/logs/do/myscript
Change the * (Mins to a meaning full time like 30, 35 ot even 42)
Check your cronlog, also paste it.
Chan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-22-2006 01:31 AM
тАО05-22-2006 01:31 AM
Re: crontab on solaris
thanks...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-22-2006 01:32 AM
тАО05-22-2006 01:32 AM
SolutionAnother technique is to source the login profiles in the script. For bash or ksh, use the . (dot or period) as the command to run the profiles as in: . /etc/profile and . $HOME/.bashrc, etc Note that if the profiles do not properly protect interactive commands (commands for terminal usage like tabs) then you'll get some warning messages about "not a typewriter" because cron has no terminal.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-22-2006 01:36 AM
тАО05-22-2006 01:36 AM
Re: crontab on solaris
Check what Bill said.
Try so that you can get the log file. Change your script accordingly. Check the /tmp/t.log
00 15 * * 1-5 /tmp/t.sh >/tmp/t.log 2>&1
Chan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-22-2006 06:04 PM
тАО05-22-2006 06:04 PM
Re: crontab on solaris
But I am new in solaris...and this is machine in production...and before I do anything let me ask U one more thing..
when I type env I get all those variables..can I just copy them as they are and inport it simply in headear of my script??
justi like this:
myscript:
#!/bin/sh
d=`date +%d%m%y%H%M%S`
dir="/opt/tomcat/logs"
/bin/rm $dir/me/old
/bin/mv $dir/me/new $dir/me/old
/bin/cp $dir/catalina.out $dir/me/new
/bin/diff $dir/me/new $dir/me/old > $dir/me/diffre
/bin/chmod 777 $dir/me/diffre
/bin/grep "no stack trace available" $dir/me/diffre > $dir/me/newfile
...
....
......
and bake my script like this:
#!/bin/sh
_=/usr/bin/env
MANPATH=/usr/share/man:/usr/local/man
HZ=100
LC_MONETARY=en_US
LC_TIME=en_US
PATH=/usr/sbin:/usr/bin:/usr/local/bin:.:/usr/opt/SUNWmd/sbin
LOGNAME=me
MAIL=/var/mail/me
PS1=anes@machine:$PWD
>
LC_MESSAGES=C
LC_CTYPE=en_US
SHELL=/usr/bin/ksh
HOME=/home1/scriptPOOL
LC_COLLATE=en_US
LC_NUMERIC=en_US
TERM=vt100
PWD=/home1/scriptPOOL
TZ=MET
d=`date +%d%m%y%H%M%S`
dir="/opt/tomcat/logs"
/bin/rm $dir/me/old
/bin/mv $dir/me/new $dir/me/old
/bin/cp $dir/catalina.out $dir/me/new
/bin/diff $dir/me/new $dir/me/old > $dir/me/diffre
/bin/chmod 777 $dir/me/diffre
/bin/grep "error" $dir/me/diffre > $dir/me/newfile
...
....
......
if I understand Bill ok??
Thanks in advance..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-22-2006 06:06 PM
тАО05-22-2006 06:06 PM
Re: crontab on solaris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-22-2006 09:45 PM
тАО05-22-2006 09:45 PM
Re: crontab on solaris
Hope this note will help...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-22-2006 11:25 PM
тАО05-22-2006 11:25 PM
Re: crontab on solaris
* 14,15 * * * /path/to/my/script
so that means script executes every minute I thought that means only on 2PM and on 3PM..I was wrong..it was executing every minute..:)
thanks everyone thru this I learned a lot more things..:)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-23-2006 12:19 AM
тАО05-23-2006 12:19 AM
Re: crontab on solaris
My question have you tried running the script once, not every minute, see below. change your script to log you error and post the errors.
Cat /tmp/t.log will give you the errors. Post that log.
00 15 * * 1-5 /tmp/myscript >/tmp/t.log 2>&1
Chan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-23-2006 01:55 AM
тАО05-23-2006 01:55 AM
Re: crontab on solaris
> #!/bin/sh
> d=`date +%d%m%y%H%M%S`
> dir="/opt/tomcat/logs"
> /bin/rm $dir/me/old
> /bin/mv $dir/me/new $dir/me/old
> /bin/cp $dir/catalina.out $dir/me/new
>
> /bin/diff $dir/me/new $dir/me/old > $dir/me/diffre
>
> /bin/chmod 777 $dir/me/diffre
> /bin/grep "no stack trace available" $dir/me/diffre > $dir/me/newfile
then you don't need any additional variables defined. I misunderstood the problem as one where the script was failing with error messages or not performing the required task. It sounds like the script is just running too many times which is simply specifying the cron values correctly.
Here is a simplified version of your script:
#!/bin/sh
PATH=/bin
set -u
d=`date +%d%m%y%H%M%S`
dir="/opt/tomcat/logs"
rm $dir/me/old
mv $dir/me/new $dir/me/old
cp $dir/catalina.out $dir/me/new
diff $dir/me/new $dir/me/old > $dir/me/diffre
chmod 777 $dir/me/diffre
grep "no stack trace available" $dir/me/diffre > $dir/me/newfile
By defining PATH local to the script, you don't need fullpaths for the commands. If you are concerned about aliases (ie, alias rm="rm -i") these won't occur in cron because cron does not login.
The set -u is a relaibility control -- it prevent spelling errors from creating problems. If you misspell a variable name and try to use it, the script will create an error message and stop before any damage is done.
I would also change the chmod 777 to a secure value of 644. 777 has two major problems:
1. You are making the diffre file executable and this file is not a program or sctipt. Never add the executable bit to data files.
2. The file is world-writable and therefore can be destroyed by anyone on your system, either by accident or maliciously. 777 (or 666) permissions are red flags that say to the world: "destroy me"
Most new people in Unix see an error like "permision denied" and quickly change the permissions to 777. But when this does not fix the problem, the bad permissions are left and bad things happen. Always determine the real reason for permission problems . Otherwise, your system will become unstable over time.
As far as your cron entry, a * means all occurances (ie, every day, every hour, every minute, etc). If what you want is for the script to run at 2pm and 3pm, then pick which minute you want to run, perhaps 2:10pm and 3:10pm and your cron entry becomes:
10 14,15 * * * /path_to_script/myscript
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-24-2006 11:23 PM
тАО05-24-2006 11:23 PM
Re: crontab on solaris
Bill Hassell Thank You very much for your help and time..I do appreciate it..
thanks everyone for useful hints..