Databases
cancel
Showing results for 
Search instead for 
Did you mean: 

/etc/profile Specify a parameter with this command

SOLVED
Go to solution
Don Jessen
Occasional Contributor

/etc/profile Specify a parameter with this command

When I log in to UNIX the /etc/profile script seems to run fine. When we
su - sybase -c "/path/to/script_name"
thru a cron job we get this error. How can I not get this error?

Usage: who [-rbtpludAasHTqRm] [am i] [utmp_like_file]

r run level
b boot time
t time changes
p processes other than getty or users
l login processes
u useful information
d dead processes
A accounting information
a all (rbtpludA options)
s short form of who (no time since last output or pid)
H print header
T status of tty (+ writable, - not writable, x exclusive open, ? hung)
q quick who
R print host name
/etc/profile[45]: test: Specify a parameter with this command.
5 REPLIES
IT_2007
Honored Contributor

Re: /etc/profile Specify a parameter with this command

Do you want to run the job as root or as sybase?

If it is syabse then allow sybase to run by adding into cron.allow
Peter Godron
Honored Contributor

Re: /etc/profile Specify a parameter with this command

Don,
if you running through cron, you don't have a terminal attached to the process.
So your who command will not work, if you are looking for session information. If the result of the who command is undefined, your test in line 45 will have nothing to compare.

Change your /etc/profile to check wether you are running from termianl or cron.
Jonathan Fife
Honored Contributor
Solution

Re: /etc/profile Specify a parameter with this command

Look at /etc/profile and see what is on line 45. I suspect it will have something to do with a tty which isn't being set since you're running it from cron.

All commands having to do with an interactive tty should be encased in an

if [ -t 0 ]; then
... # interactive
else
... # not interactive
fi

block.

HTH
Decay is inherent in all compounded things. Strive on with diligence
Victor BERRIDGE
Honored Contributor

Re: /etc/profile Specify a parameter with this command

Hi,
Launching a job by cron means batch mode, /etc/profile tests your terminal... there is no easy way to bypass, the best would be if you need the env setting of sybase to recuperate what you need in a lets say profile.sybase, put this in your /path/to/script_name at the beginning like . /path/to/profile.sybase and execute your cron line su without the -:
su sybase -c "/path/to/script_name"
Or you would have to add tests for interactive shells in /etc/profile /~HOME/sybase/.profile...


All the best
Victor
Don Jessen
Occasional Contributor

Re: /etc/profile Specify a parameter with this command

I used Jonathan's solution.
if [ -t 0 ]; then
... # interactive
else
... # not interactive
fi

It worked like a charm. Was very self documenting as to what it did, and what to do (I am not a UNIX admin).