LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-10-2004, 07:22 AM   #1
maxance
LQ Newbie
 
Registered: Jun 2004
Posts: 3

Rep: Reputation: 0
[Shell scripting] interactive and crontab pb


Hi,

If anyone could help me to resolve this pb.
Under RedHat A.S 2.1, i m coding some shell script to monitor system.
The problem comes from the crontab job executing my shell script that do not give the same output when it s launch in a bash interactive shell.
Here is some explanations : (i have identified where it could come from) here is a brief line of my shell sccript :


1/ In interactive mode (bash /bin/bash)
# sar -q | grep -v Average | tail -1| awk '{print int($3)}'
0

this should give me the last time (not average one) runq-sz column , and the result is good (machine is idle 100% and no runqueue process)

2/ But In root crontab (SHELL=/bin/bash) :
# crontab -l
* * * * * echo "`sar -q | grep -v Average | tail -1| awk '{print int($3)}'`"
#
the result each minute gaves me :
63

It returns the 4th column of sar -q which is the plist-sz column.

How does it give different result ? It looks like the double | or the tail command does not act in the same way as in interactive mode.
Any ideas of this interpretation would be welcome

Thanks in advance
 
Old 06-10-2004, 09:16 AM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
I don't see anything a priori - but -

cron execs the script without running any login scripts - in other words your PATH and other variables may not be defined or not defined the way they are in an interactive session. This is expected behavior. Test your script in an environment where nothing is defined. Make it work there, then it will work anywhere.
 
Old 06-10-2004, 10:38 AM   #3
maxance
LQ Newbie
 
Registered: Jun 2004
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks for your answer, I first think of such environment variables problem but i do not see what the different between my crontab environment variable :

# cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

and the shell interactive bash variable

# env
PWD=/users/AdmPlat
HOSTNAME=udgil131
LESSOPEN=|/usr/bin/lesspipe.sh %s
USER=root
LS_COLORS=no=00:fi=00:di=01;34:ln=01;36i=40;33:so=01;35:bd=40;33;01:cd=40;33;01r=01;05;37;41:mi= 01;05;37;41:ex=01;32:*.cmd=01;32:*.exe=01;32:*.com=01;32:*.btm=01;32:*.bat=01;32:*.sh=01;32:*.csh=01 ;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz =01;31:*.bz2=01;31:*.bz=01;31:*.tz=01;31:*.rpm=01;31:*.cpio=01;31:*.jpg=01;35:*.gif=01;35:*.bmp=01;3 5:*.xbm=01;35:*.xpm=01;35:*.png=01;35:*.tif=01;35:
MACHTYPE=i386-redhat-linux-gnu
MAIL=/var/spool/mail/root
INPUTRC=/etc/inputrc
BASH_ENV=/root/.bashrc
LANG=en_US
LOGNAME=root
SHLVL=1
SHELL=/bin/bash
USERNAME=root
HOSTTYPE=i386
OSTYPE=linux-gnu
HISTSIZE=1000
TERM=xterm
HOME=/root
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/usr/bin/X11:/usr/X11R6/bin:/root/bin
_=/usr/bin/env
OLDPWD=/users/AdmPlat/RPMS/RPMS/i386
 
Old 06-10-2004, 10:43 AM   #4
maxance
LQ Newbie
 
Registered: Jun 2004
Posts: 3

Original Poster
Rep: Reputation: 0
Think i have found the bug.. it comes from the 2 first sar Column standard output:

under root :
# XX:XX:XX PM

under another user shell sar doesn t give the same output
there isn t any PM/AM time format but a 24h format XX:XX:XX
 
Old 06-10-2004, 12:00 PM   #5
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
Which is controlled by the LC_TIME environment variable.

Type man locale for a full discussion.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Making shell scripts interactive using dialog saurabh142857 Programming 2 01-03-2005 11:14 AM
Run interactive program in shell escargot22026 Programming 4 08-14-2004 11:59 PM
Building an interactive menu in perl for use as a shell jon_k Linux - Software 2 05-16-2004 09:55 PM
Building an interactive menu in perl for use as a shell jon_k Linux - General 0 05-15-2004 03:23 PM
Where is the shell interactive for ruby languaje? Manuel Tejada Red Hat 5 02-02-2004 08:30 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:38 PM.

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