1

The purpose of the script is to login to multiple servers and execute the df -k command and to send out email containing the list similar like below : Thu Nov 3 12:59:49 EDT 2016

Running out of space "/opt (80%)" on (a******001s02)

Running out of space "/var (83%)" on (a*******01s01)

Running out of space "/opt/IBM/ITM (98%)" on (a*******001s01)

Running out of space "/apps (80%)" on (a*********01s01)

Running out of space "/opt/wily (80%)" on (a********01s01)

My challenge is : This script has to run as a scheduled job like autosys job . And the challenge is that, what i believe(not 100 percent sure) , the username ( ssh $username@$host) should be a sudo user for it to run as an autosys job. But if i hardcode username as a sudo user , the ssh command wont work . As in , we cannot login to multiple servers with username as sudo. Here I have used 'logname' , so logname will take the name of the user executing the command .But , logname doesnt seem to work if i have to make it as autosys job .

Basically what I want is to make this script run as an autosys job. Currently its working perfectly fine If I can manually run the script .I appreciate any help. Thanks in advance :)

Entire script:

#Shell script to watch disk space
#!/bin/sh

MAILTO="xxxxxxx@xxxxx.com"


# Set alert level 80% is default


ALERT=70

path=/tmp/Joshma

report=$path/report.txt

date > $report

echo >>$report

servers=$path/serversfile.txt

username=`logname`

for host in `cat $servers`   

do 
echo "$host"
ssh $username@$host df -k | grep -vE '^Filesystem|tmpfs|cdrom|proc' | awk '{ print $4 " " $7 }' | while read output;

do
echo " $output" 

usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1  )

partition=$(echo $output | awk '{ print $2 }' )

if [ $usep -ge $ALERT ] 
then
    echo "Running out of space \"$partition ($usep%)\" on ($host)\n" >>$report 

fi

done

done

cat $report | mail -s "File System Space Check" $MAILTO
Alexander Farber
  • 21,519
  • 75
  • 241
  • 416
  • What gets me confused is that nothing in the command run on the remote machine needs sudoer access. Do you have an error message from `autosys` to help us understanding your problem better? – jraynal Mar 11 '17 at 14:40

1 Answers1

0

The job owner value in a Autosys job can be any user ID that can logon to the server (The machine value) that is executing the AutoSys job. The AutoSys agent will spawn a child process that executes the command as that user ID. Use the ID that you are using to manual run the script as the job owner if you can. If not make sure that the ID that you use has the appropriate permissions to ssh to your server and execute the commands. It is not a AutoSys requirement that the job owner value have sudo on a server.

If the script runs manually but fails in the AutoSys job using the same ID and server, start looking at the environment set in child process. By default AutoSys sources a generic profile that may not be the same as the one set when logging in manually with the ID. You may have to set the profile: value in the job to source a profile file to set the environment correctly when the child process is started.

clmccomas
  • 684
  • 6
  • 8