How can I execute a script on AIX after my own .profile/.kshrc takes effect?

1.2k views Asked by At

background: My colleagues and I all login a AIX server with user "root", after login everyone loads their .profile/.kshrc/.netrc etc., then start their work, to execute their own shell scripts.

problem: when I crontab a script, it will fail because some cmds in it is only defined in my own environment. The failure remains even I add the sentences of source the .profile/.kshrc/.netrc in the script. It appears it just can not remember the former system setting.

question: How can I edit the script to get the task ran on my own environment?

1

There are 1 answers

0
Henk Langeveld On

A script run by cron should set its own PATH to assure it's starting from a known situation.

Make an inventory of all external commands used by the script, list the directories where they live, then add a line to the top of the script:

PATH=/first/dir:/second/dir

Etc...

In most case you want to include /usr/bin and/or /bin -- for scripts run as root /usr/sbin is another favourite.