0

I am new to SysAdmin (in Redhat) and need to correct a non-functioning shell script. The .sh file was originally running on a Solaris Unix system.

There is an associated CRON job which launches the script to run a jar file, email the run results to SysAdmins, and then copy the run results to a specific location in the system.

I have already made some substantial changes already, but two parts are not working:

  1. Sending email: the subject line, and to fields are not displayed, although the email is sent with the run results.

  2. Copying the run results file and moving to a new system location

I am wondering if my ${} syntax is incorrect in these two parts. The jar file runs correctly.

#!/bin/sh

#Declare the required paths
JAVA=/usr/local/...../jdk/jre/bin/java
CLASSPATH=/usr/local/..../apps/JavaProg

#Declare the logging params
LOGPATH=/usr/local/..../logs #removed spaces either side of assignment
LOGDTTM=$(date +"%Y-%m-%d")  #moved + sign to left of " 

#Declare the email params
ADMINS=admin1@company.co.uk,admin2@company.co.uk
SUBJECT="Results: Run File"
FROM=donotreply@company.co.uk

#Change to the javaprog.jar location 
cd ${CLASSPATH}

#Run the jar file
${JAVA} -jar ${CLASSPATH}/javaprog.jar

#Send an email to the SysAdmin with the output of the javaprogrun.log
#echo -e "Subject: ${SUBJECT}" | 
#cat - javaprogrun.log |
#/usr/sbin/sendmail  -f "${FROM}"  -t "${ADMINS}" 

#above section replaced with:
BODY=javaprogrun.log
(cat-${BODY})<<EOF|/usr/sbin/sendmail -i ${ADMINS}
Subject:$SUBJECT
To:${ADMINS}
From:${FROM}
EOF


#Copy the log run file into new file format and move to the logs directory
mv javaprogrun.log  ${LOGPATH}/xxx-javaprogrun-b2.${LOGDTTM}.log 

When I have googled for Sendmail I am getting lots of different options to resolve this issue, but as I don't currently have access to a RedHat environment ... don't ask... I am unable to test locally. The script has to be sent to a third party to install.

EDIT: I resolved my issues and have added the tweaks I made to my code. The script now sends an email correctly with the run results output sent as a file, and moves the generated timestamped file into the correct system location.

  • Copying the run results file and moving to a new system location How does that "not work"? Assuming this entire script is run via cron, what does the crontab entry look like? Is there any output from the cron job? – Andrew Henle Jul 24 at 10:16
  • @AndrewHenle I have no access to the actual RedHat System on which this script is being installed, so working blind here. But the log file does not appear at the GUI entry point. The cron job just runs the script at a specify time. – Beckteck Jul 24 at 10:37
  • I have no access to the actual RedHat System on which this script is being installed But you're expected to fix it?!?!?! The problem can easily be specific to that machine - for all you know the system could have a weird cat executable that gets run because of some local $PATH value. Can you get something like VirtualBox and at least run a RH virtual machine? – Andrew Henle Jul 24 at 10:59
  • @AndrewHenle Hmm yes... :-D . I was considering doing exactly that, but wondered if I was missing something obvious. Hence asking the question. – Beckteck Jul 24 at 11:08
  • Assignments can't have spaces around the equal sign. – Kusalananda Jul 24 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.