It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Below script is to push file to remote location through sftp,i faced lot of issues to write below code.But still i am facing some issue,Please guid me to resolve the issues.It's not working with sh.it is only working with ksh.
#test script
#-------------------------------------------------------------------
#!/bin/sh
#------------------------------------------------------------------------
# sftp_file_uploads.sh
#------------------------------------------------------------------------
export REMOTE_SERVER_PROD='192.168.0.1'
export REMOTE_SERVER_FAILOVER='192.168.0.2'
export SFTP_PORT='0001'
export SOURCE_FUNCTIONAL_ID='testusr'
export SOURCE_FILE_DIRECTORY='/var/temp/files/'
export SOURCE_ARCHIVE_DIRECTORY='/var/temp/files/archive'
export DATE_FORMAT=`date "+%Y%m%d"`
export LOG_DIRECTORY='/var/temp/logs'
export DESTINATION_FILE_DIRECTORY='/dest'
export LOG_FILE='$LOG_DIRECTORY/test_$DATE_FORMAT.log'
export SFTP_BATCH_FILE='/var/tmp/SFTP_BATCH_FILE'
#------------------------------------------------------------------------
# Find if the files are available at the source directory.
#------------------------------------------------------------------------
cd $SOURCE_FILE_DIRECTORY
export FILE_TO_UPLOAD_TESTD=`ls -lrt TESTD$DATE_FORMAT.csv | awk '/TESTD/{ f=$NF };END{ print f }'`
export FILE_TO_UPLOAD_TESTDF=`ls -lrt TESTDF$DATE_FORMAT.csv | awk '/TESTDF/{ f=$NF };END{ print f }'`
#------------------------------------------------------------------------
# Try 2 times and Sleep for 5 mins if either of the files is not present
#------------------------------------------------------------------------
counter=0
flag_file_found_TESTD=0
flag_file_found_TESTDF=0
while [ $counter –lt 2 ]
do
#---------------------------
# Check TESTD file arrived
#---------------------------
if [ -z $FILE_TO_UPLOAD_TESTD ] then
echo “No TESTD file to transfer. Sleeping for 5 mins” >> $LOG_FILE
sleep 300
else
echo “TESTD file found to transfer.” >> $LOG_FILE
flag_file_found_TESTD=1
fi
#---------------------------
# Check TESTDF file arrived
#---------------------------
if [ -z $FILE_TO_UPLOAD_TESTDF ] then
echo “No TESTDF file to transfer. Sleeping for 5 mins” >> $LOG_FILE
sleep 300
else
echo “TESTDF file found to transfer.” >> $LOG_FILE
flag_file_found_TESTDF =1
fi
if [[ flag_file_found_TESTD == 1 &&
flag_file_found_TESTDF == 1 ]] then
echo “Both files are found.” >> $LOG_FILE
break
else
echo “At least one of the files is not found. Retrying now.” >> $LOG_FILE
fi
counter=`expr $counter + 1`
done
if [[ flag_file_found_TESTD == 1 &&
flag_file_found_TESTDF == 1 ]] then
echo “Both files are found.”
break
else
if [ flag_file_found_TESTD == 0 ] then
echo “test file is not found and two attempts completed. Cannot transfer the file for today.” >> $LOG_FILE
fi
if [flag_file_found_TESTDF == 0 ] then
echo “test1 file is not found and two attempts completed. Cannot transfer the file for today.” >> $LOG_FILE
fi
fi
#------------------------------------------------------------------------
# Create sftp script
#------------------------------------------------------------------------
rm -f $SFTP_BATCH_FILE
echo "lcd $SOURCE_FILE_DIRECTORY " > $SFTP_BATCH_FILE
echo "cd $DESTINATION_FILE_DIRECTORY " >> $SFTP_BATCH_FILE
if [ -z $FILE_TO_UPLOAD_TESTD ] then
echo "put $FILE_TO_UPLOAD_TESTD " >> $SFTP_BATCH_FILE
fi
if [ -z $FILE_TO_UPLOAD_TESTDF ] then
echo "put $FILE_TO_UPLOAD_TESTDF " >> $SFTP_BATCH_FILE
fi
echo "bye" >> $SFTP_BATCH_FILE
#------------------------------------------------------------------------
# Do sftp
#------------------------------------------------------------------------
echo " Before SFTP " >> $LOG_FILE
if [[ -z $ FILE_TO_UPLOAD && -z $ FILE_TO_UPLOAD1 ]] then
echo “No files to transfer” >> $LOG_FILE
mv $LOG_FILE $LOG_DIRECTORY
exit 1
else
echo “Attempting to connect to Remote Server $REMOTE_SERVER_PROD” >> $LOG_FILE
/usr/bin/sftp –v -oPort=$SFTP_PORT -b $SFTP_BATCH_FILE $SOURCE_FUNCTIONAL_ID#$REMOTE_SERVER_PROD >> $LOG_FILE 2 >> $LOG_FILE
fi
result=$?
errorConnectToProd=0
if [ $result -eq 0 ]
then
echo "SFTP completed successfully to Prod Remote Server" >> $LOG_FILE
else
errorConnectToProd=1
if [[ $result -eq 4 || $result -eq 5 ]]
echo "FAILED to connect to Server. " >> $LOG_FILE
else
echo "FAILED to SFTP to Remote Server. " >> $LOG_FILE
fi
fi
if [ errorConnectToProd == 1 ] then
echo “Attempting to connect to FAILOVER Remote Server $REMOTE_SERVER_FAILOVER” >> $LOG_FILE
/usr/bin/sftp –v -oPort=$SFTP_PORT -b $SFTP_BATCH_FILE $SOURCE_FUNCTIONAL_ID#$REMOTE_SERVER_FAILOVER >> $LOG_FILE 2 >> $LOG_FILE
fi
result=$?
if [ $result -eq 0 ]
then
echo "SFTP completed successfully to Failover Remote Server" >> $LOG_FILE
else
echo "FAILED to SFTP to Failover Remote Server. " >> $LOG_FILE
mv $LOG_FILE $LOG_DIRECTORY
exit 1
fi
fi
cd $SOURCE_FILE_DIRECTORY
mv $FILE_TO_UPLOAD_TESTD $SOURCE_ARCHIVE_DIRECTORY
echo “Moved $FILE_TO_UPLOAD_TESTD to archive direcotry.” >> $LOG_FILE
mv $FILE_TO_UPLOAD_TESTDF $SOURCE_ARCHIVE_DIRECTORY
echo “Moved $FILE_TO_UPLOAD_TESTDF to archive direcotry.” >> $LOG_FILE
rm -f $SFTP_BATCH_FILE
echo “Deleted the SFTP Batch file.” >> $LOG_FILE
echo “Upload completed.” >> $LOG_FILE
mv $LOG_FILE $LOG_DIRECTORY
exit 0
Getting below Errors:
test.ksh[41]: $LOG_DIRECTORY/test_$DATE_FORMAT.log: cannot create
test.ksh[55]: $LOG_DIRECTORY/test_$DATE_FORMAT.log: cannot create
test.ksh[56]: flag_file_found_TESTDF: not found
test.ksh[65]: $LOG_DIRECTORY/test_$DATE_FORMAT.log: cannot create
test.ksh[41]: $LOG_DIRECTORY/test_$DATE_FORMAT.log: cannot create
test.ksh[55]: $LOG_DIRECTORY/test_$DATE_FORMAT.log: cannot create
test.ksh[56]: flag_file_found_TESTNDF: not found
test.ksh[65]: $LOG_DIRECTORY/test_$DATE_FORMAT.log: cannot create
test.ksh[79]: [flag_file_found_TESTDF: not found
rm: /var/tmp/SFTP_BATCH_FILE is a directory
test.ksh[89]: /var/tmp/SFTP_BATCH_FILE: cannot create
test.ksh[90]: /var/tmp/SFTP_BATCH_FILE: cannot create
test.ksh[97]: B: not found
test.ksh[98]: B: not found
test.ksh[99]: B: not found
test.ksh[100]: B: not found
test.ksh[101]: B: not found
test.ksh[102]: B: not found
test.ksh[106]: /var/tmp/SFTP_BATCH_FILE: cannot create
test.ksh[113]: $LOG_DIRECTORY/test_$DATE_FORMAT.log: cannot create
test.ksh[114]: syntax error at line 114 : `FILE_TO_UPLOAD' unexpected
Regards,
Chai
This line is wrong:
export LOG_FILE='$LOG_DIRECTORY/test_$DATE_FORMAT.log'
It should use double quotes, so that the variables will be expanded:
export LOG_FILE="$LOG_DIRECTORY/test_$DATE_FORMAT.log"
Another error:
if [flag_file_found_TESTDF == 0 ] then
needs a space after [. [ is a command (it's a synonym for test), and all commands are separated from their arguments by spaces.
The whole section labeled "Create sftp script" is failing because /var/tmp/SFTP_BATCH_FILE already exists and is a directory; rm -f won't delete a directory, you need to use rm -rf.
if [[ flag_file_found_TESTD == 1 &&
flag_file_found_TESTDF == 1 ]] then
is missing the $ before the variable names.
if [[ -z $ FILE_TO_UPLOAD && -z $ FILE_TO_UPLOAD1 ]] then
Get rid of the space after $.
UPDATE 2:
In all your if statements, you're missing the ; (or newline) before then.
I'm not sure what's causing all the "B: not found" errors. But after you fix all the other errors, maybe it will go away or be easier to find.
Related
I am trying to use the following bash script to login to a remote ftp and delete files older than N days old. Script says it is working and does not give an error - but files are not being deleted. What am I missing? Or is there a better way to do this? Keep in mind this is only a remote FTP and not SSH so I can NOT use the mtime function is why I am trying to do this. Can anyone help?
The usage is all commands - here is what I am using via ssh to run the script
./ftprem.sh -s ftp.server.com -u myusername -p mypassword -f /directory -d 3
#!/bin/bash
PROGNAME=$(basename $0)
OUTFILE="/tmp/ftplist.$RANDOM.txt"
CMDFILE="/tmp/ftpcmd.$RANDOM.txt"
ndays=14
print_usage() {
echo ""
echo "$PROGNAME - Delete files older than N days from an FTP server"
echo ""
echo "Usage: $PROGNAME -s -u -p -f (-d)"
echo ""
echo " -s FTP Server name"
echo " -u User Name"
echo " -p Password"
echo " -f Folder"
echo " -d Number of Days (Default: $ndays)"
echo " -h Show this page"
echo ""
echo "Usage: $PROGNAME -h"
echo ""
exit
}
# Parse parameters
options=':hs:u:p:f:d:'
while getopts $options flag
do
case $flag in
s)
FTPSITE=$OPTARG
;;
u)
FTPUSER=$OPTARG
;;
p)
FTPPASS=$OPTARG
;;
f)
FTPDIR=$OPTARG
;;
d)
ndays=$OPTARG
;;
h)
print_usage
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
shift $(($OPTIND - 1))
if [[ -z "$FTPSITE" || -z "$FTPUSER" || -z "$FTPPASS" || -z "$FTPDIR" ]];
then
echo "ERROR: Missing parameters"
print_usage
fi
# work out our cutoff date
TDATE=`date --date="$ndays days ago" +%Y%m%d`
echo FTP Site: $FTPSITE
echo FTP User: $FTPUSER
echo FTP Password: $FTPPASS
echo FTP Folder: $FTPDIR
echo Removing files older than $TDATE
# get directory listing from remote source
ftp -i -n $FTPSITE <<EOMYF > /dev/null
user $FTPUSER $FTPPASS
binary
cd $FTPDIR
ls -l $OUTFILE
quit
EOMYF
if [ -f "$OUTFILE" ]
then
# Load the listing file into an array
lista=($(<$OUTFILE))
# Create the FTP command file to delete the files
echo "user $FTPUSER $FTPPASS" > $CMDFILE
echo "binary" >> $CMDFILE
echo "cd $FTPDIR" >> $CMDFILE
COUNT=0
# loop over our files
for ((FNO=0; FNO<${#lista[#]}; FNO+=9));do
# month (element 5), day (element 6) and filename (element 8)
FMM=${lista[`expr $FNO+5`]}
FDD=${lista[`expr $FNO+6`]}
FYY=${lista[`expr $FNO+7`]}
if [[ $FYY == *\:* ]]
then
FDATE=`date -d "$FMM $FDD" +'%Y%m%d'`
else
FDATE=`date -d "$FMM $FDD $FYY" +'%Y%m%d'`
fi
# echo $FDATE
# check the date stamp
if [[ $FDATE -lt $TDATE ]];
then
echo "Deleting ${lista[`expr $FNO+8`]}"
echo "delete ${lista[`expr $FNO+8`]}" >> $CMDFILE
COUNT=$[$COUNT + 1]
fi
done
echo "quit" >> $CMDFILE
if [[ $COUNT -gt 0 ]];
then
cat $CMDFILE | tr -d "\r" > $CMDFILE
ftp -i -n $FTPSITE < $CMDFILE > /dev/null
else
echo "Nothing to delete"
fi
rm -f $OUTFILE $CMDFILE
fi
If this helps your debugging...
In the# Parse parameter section of the script, the options variable your have just before the case block has value options=':hs:u:p:f:d:' instead of options=':h:s:u:p:f:d:'
I thought i should point that out.
I want to check for file in directory if there then push it to ssh server checing server connection if file not there then try 3 times with each 1min interval and in between if it comes ( on 2nd attend for example) then try again to connect ssh and push. else check for 3 attempts and exit
Please check my below code it is halting after 1st attempt ( during 2nd attempt I am making file available)
#!/bin/sh
echo "OK, start pushing the Userdetails to COUPA now..."
cd /usr/App/ss/outbound/usrdtl/
n=0
until [ $n -ge 3 ] || [ ! -f /usr/App/ss/outbound/usrdtl/USERS_APPROVERS_*.csv ]
do
if [ -f /usr/App/ss/outbound/usrdtl/USERS_APPROVERS_*.csv ] ;
then
pushFiles()
else
n=$[$n+1]
sleep 60
echo " trying " $n "times "
fi
done
pushFiles()
{
echo "File present Now try SSH connection"
while [ $? -eq 0 ];
do
echo $(date);
scpg3 -v /usr/App/ss/outbound/usrdtl/USERS_APPROVERS_*.csv <sshHost>:/Incoming/Users/
if [ $? -eq 0 ]; then
echo "Successfull"
echo $(date);
echo "Successfull" >> /usr/App/ss/UserApproverDetails.log
exit 1;
else
echo $(date);
echo "Failed" >> /usr/App/ss/UserApproverDetails.log
echo "trying again to push file.."
scpg3 -v /usr/App/sg/outbound/usrdtl/USERS_APPROVERS_*.csv <ssh Host>:/Incoming/Users/
echo $(date);
exit 1;
fi
done
}
I've tried to simplify this code for you. I hope it helps:
#!/bin/bash
outdir="/usr/App/ss/outbound/usrdtl"
logfile="/usr/App/ss/UserApproverDetails.log"
file_prefix="USERS_APPROVERS_"
function push_files() {
echo "File present now try SSH connection"
local attempts=1
local retries=2
date
while [[ ${attempts} -lt ${retries} ]]; do
if scp ${outdir}/${file_prefix}*.csv <sshHost>:/Incoming/Users/ ; then
echo "Successful" | tee -a ${logfile}
date
exit 0
else
echo "Failed" >> ${logfile}
fi
attempts=$((attempts+1))
do
echo "scp failed twice" | tee -a ${logfile}
exit 2
}
echo "OK, start pushing the Userdetails to COUPA now..."
cd ${outdir}
attempts=1
retries=3
while [[ ${attempts} -lt ${retries} ]]; do
echo "looking for files...attempt ${attempts}"
if test -n "$(shopt -s nullglob; echo ${outdir}/${file_prefix}*.csv)"; then
push_files()
fi
attempts=$((attempts+1))
sleep 60
done
echo "Files were never found" | tee -a ${logfile}
exit 1
Look at this code and tell me how it's not doing what you're trying to do. The most complicated part here is the nullglob stuff, which is a handy trick to see if any file in a glob matches
Also, I generally used bashisms.
have some problem with shell script.
In our office we set up only few commands, that available for devs when they are trying ssh to server. It is configured with help of .ssh/authorized_keys file and available command for user there is bash script:
#!/bin/sh
if [[ $1 == "--help" ]]; then
cat <<"EOF"
This script has the purpose to let people remote execute certain commands without logging into the system.
For this they NEED to have a homedir on this system and uploaded their RSA public key to .ssh/authorized_keys (via ssh-copy-id)
Then you can alter that file and add some commands in front of their key eg :
command="/usr/bin/dev.sh",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty
The user will do the following : ssh testuser#server tail testserver.example.com/2017/01/01/user.log
EOF
exit 0;
fi
# set global variable
set $SSH_ORIGINAL_COMMAND
# set the syslog path where the files can be found
PATH="/opt/syslog/logs"
# strip ; or any other unwanted signs out of the command, this prevents them from breaking out of the setup command
if [[ $1 != "" ]]; then
COMMAND=$1
COMMAND=${COMMAND//[;\`]/}
fi
if [[ $2 != "" ]]; then
ARGU1=$2
ARGU1=${ARGU1//[;\`]/}
fi
if [[ $3 != "" ]]; then
ARGU2=$3
ARGU2=${ARGU2//[;\`]/}
fi
if [[ $4 != "" ]]; then
ARGU3=$4
ARGU3=${ARGU3//[;\`]/}
fi
# checking for the commands
case "$COMMAND" in
less)
ARGU2=${ARGU1//\.\./}
FILE=$PATH/$ARGU1
if [ ! -f $FILE ]; then
echo "File doesn't exist"
exit 1;
fi
#echo " --------------------------------- LESS $FILE"
/usr/bin/less $FILE
;;
grep)
if [[ $ARGU2 == "" ]]; then
echo "Pls give a filename"
exit 1
fi
if [[ $ARGU1 == "" ]]; then
echo "Pls give a string to search for"
exit 1
fi
ARGU2=${ARGU2//\.\./}
FILE=$PATH/$ARGU2
/usr/bin/logger -t restricted-command -- "------- $USER Executing grep $ARGU1 \"$ARGU2\" $FILE"
if [ ! -f $FILE ]; then
echo "File doesn't exist"
/usr/bin/logger -t restricted-command -- "$USER Executing $#"
exit 1;
fi
/bin/grep $ARGU1 $FILE
;;
tail)
if [[ $ARGU1 == "" ]]; then
echo "Pls give a filename"
exit 1
fi
ARGU1=${ARGU1//\.\./}
FILE=$PATH/$ARGU1
if [ ! -f $FILE ]; then
echo "File doesn't exist"
/usr/bin/logger -t restricted-command -- "$USER Executing $# ($FILE)"
exit 1;
fi
/usr/bin/tail -f $FILE
;;
cat)
ARGU2=${ARGU1//\.\./}
FILE=$PATH/$ARGU1
if [ ! -f $FILE ]; then
echo "File doesn't exist"
exit 1;
fi
/bin/cat $FILE
;;
help)
/bin/cat <<"EOF"
# less LOGNAME (eg less testserver.example.com/YYYY/MM/DD/logfile.log)
# grep [ARGUMENT] LOGNAME
# tail LOGNAME (eg tail testserver.example.com/YYYY/MM/DD/logfile.log)
# cat LOGNAME (eg cat testserver.example.com/YYYY/MM/DD/logfile.log)
In total the command looks like this : ssh user#testserver.example.com COMMAND [ARGUMENT] LOGFILE
EOF
/usr/bin/logger -t restricted-command -- "$USER HELP requested $#"
exit 1
;;
*)
/usr/bin/logger -s -t restricted-command -- "$USER Invalid command $#"
exit 1
;;
esac
/usr/bin/logger -t restricted-command -- "$USER Executing $#"
The problem is next:
when i try to exec some command, it takes only first argument, if i do recursion in files by using {n,n1,n2} - it doesn't work:
[testuser#local ~]$ ssh testuser#syslog.server less srv1838.example.com/2017/02/10/local1.log |grep 'srv2010' | wc -l
0
[testuser#local ~]$ ssh testuser#syslog.server less srv2010.example.com/2017/02/10/local1.log |grep 'srv2010' | wc -l
11591
[testuser#local ~]$ ssh testuser#syslog.server less srv{1838,2010}.example.com/2017/02/10/local1.log |grep 'srv2010' | wc -l
0
[testuser#local ~]$ ssh testuser#syslog.server less srv{2010,1838}.example.com/2017/02/21/local1.log |grep 'srv2010' | wc -l
11591
Could someone help me, how can i parse\count command arguments to make it work?
Thank you and have a nice day!
The number of arguments for a bash script would be $#. As a quick example:
#!/bin/bash
narg=$#
typeset -i i
i=1
while [ $i -le $narg ] ; do
echo " $# $i: $1"
shift
i=$i+1
done
gives, for bash tst.sh a b {c,d}
4 1: a
3 2: b
2 3: c
1 4: d
In your script, the command to execute (cat, less, ...) gets explicitly only the second argument to the script. If you want to read all arguments, you should do something like this (note: only a hint, removed all sorts of checks etc..)
command="$1"
shift
case $command in
(grep) pattern="$1"
shift
while [ $# -gt 0 ] ; do
grep "$pattern" "$1"
shift
done
;;
esac
note: added some quotes as comment suggested, but, being only a hint, you should carefully look at quoting and your checks in your own script.
Less command working now:
case "$COMMAND" in
less)
if [[ $ARGU1 == "" ]]; then
echo "Pls give a filename"
exit 1
fi
FILES_LIST=${#:2}
FILE=(${FILES_LIST//\.\./})
for v in "${FILE[#]}";do
v=${v//[;\']/}
if [ ! -f $v ]; then
echo "File doesn't exist"
fi
/usr/bin/less $PATH/$v
done;;
tail command works too with 2 and more files, but i can't execute tail -f command on two files unfortunately.
I've got my script going as far as It can connect, login and run the command. But I'm stuck as how do I save the response from the command to a file, without saving the whole session.
#!/bin/sh
Var=1
while [ $Var -lt 20 ]
do
HOST='IPa.ddr.ess.'$Var
USER='MyUser'
PASSWD='MyPassword'
CMD='MyCommand'
(
echo open "$HOST"
sleep 1
echo "$USER"
sleep 1
echo "$PASSWD"
sleep 1
echo "$CMD"
#I want to save the output from my $cmd to an varaible $Output
#Then I want to write "$HOST - $Output" to a file named "output.txt"
sleep 2
echo "exit"
) | telnet
Var=$((Var + 1))
done
I'd appreciate any help, or pointers in the right direction
Ok, this looks more challenging than I initially thought. I like it :-)
#!/bin/sh
Var=1
while [ $Var -lt 20 ]
do
HOST='IPa.ddr.ess.'$Var
USER='MyUser'
PASSWD='MyPassword'
CMD='MyCommand'
MARKER='XXXX1234:AUIE'
(echo "$HOST - " ; (
echo unset echo
echo open "$HOST"
sleep 1
echo "$USER"
sleep 1
echo "$PASSWD"
sleep 1
echo echo "$MARKER"
echo "$CMD"
#I want to save the output from my $cmd to an varaible $Output
#Then I want to write "$HOST - $Output" to a file named "output.txt"
sleep 2
echo "exit"
) | telnet | sed -e "1,/$MARKER/d" ) >> output.txt
Var=$((Var + 1))
done
What this does is:
it disables echo-ing in telnet
After the login session, it prints a marker
anything after the marker is saved into output.txt
I imbricated into yet another shell that will print the "$HOST -" part
I am having problem in understanding the following line of code ..
/home/rmsbatch/autoscript/autorms.ksh dc_load_main.ksh -q belk_dc_load_tran_data.seq
What's being done here ? what does "-q" means ? What does ".seq" file means in unix "belk_dc_load_tran_data.seq"
Please elaborate
autorms.ksh
#!/bin/ksh
################################################################################
# Description : Execute RMS Jobs with Error Reporting
#
################################################################################
. /home/rmsbatch/.profile
set -x
LOG=/logs/IBM/AutoLogs
CMNLOG=$LOG/BatchStatus_`date +"%y%m%d`.txt
if [ "${1}" == "prepost" ] || [ "${1}" == "bprepost" ]
then
exec > ${LOG}/Auto_${1}_${3}.log 2>&1
else
exec > ${LOG}/Auto_${1}.log 2>&1
fi
function Error_Log
{
# translate "\n" to "^" below
v1=$(echo -n $1 | tr "\n" "^")
v2=$(echo -n $2 | tr "\n" "^")
echo $(hostname)"|"$(basename $CMD $PARAM3)"|"$(date +%m/%d/%y)"|"$(date +%H:%M:%S)"|"$v1"|"$v2 |grep "Failed"
if [[ $? -eq 0 ]]
then
echo $(hostname)"|"$(basename $CMD $PARAM3)"|"$(date +%m/%d/%y)"|"$(date +%H:%M:%S)"|"$v1"|"$v2 | mail -s "RMS Batch Failed in PROD" rms_app_support#belk.com,bandrest#in.ibm.com,vanarsda#us.ibm.com,wgwinslo#us.ibm.com
fi
echo $(hostname)"|"$(basename $CMD $PARAM3)"|"$(date +%m/%d/%y)"|"$(date +%H:%M:%S)"|"$v1"|"$v2 >> $CMNLOG
}
function RunBatch
{
set -x
echo "Running the Batch or Script"
echo "Command" $CMD
if [[ $check -ne 1 ]]
then
ls $MMBIN/$CMD
if [ $? == 0 ] || [ $uRC -eq 0 ]
then
echo "------ Running the Command ------"
Error_Log "$(basename $CMD $PARAM3) Started"
if [ "${CMD}" == "prepost" ] || [ "${CMD}" == "bprepost" ]
then
${MMBIN}/${CMD} $PARAM1 $PARAM3 $PARAM4 $PARAM5
echo $?| read VResult
else
cd $MMBIN
$SHOME/batch_wrapper.ksh ${CMD} $PARAM1 $PARAM3 $PARAM4 $PARAM5
echo $?| read VResult
fi
if [ $VResult -eq 0 ]
then
Error_Log "$(basename $CMD $PARAM3) Batch Completed Successfully"
VResult=0
return $VResult
else
cat $MMHOME/error/err.${CMD}*.`date +"%b_%d"`|tail -1|grep error
echo $error|read Error
echo `$SHOME/batch_wrapper.ksh ${CMD} $PARAM1 $PARAM3 $PARAM4 $PARAM5`|read Error1
Error_Log "$(basename $CMD $PARAM3) Failed with - $Error Error1"
return $VResult
fi
else
echo " Command not found in the Directory "
Error_Log "$(basename $CMD $PARAM3) Failed for Command Not Found"
VResult=99
return $VResult
fi
else
echo "------ Running the Command ------"
Error_Log "$(basename $CMD $PARAM3) Started"
$MMHOME/external/scripts/$CMD.ksh $PARAM1 $PARAM3 $PARAM4 $PARAM5 $PARAM6 $PARAM7
echo $?|read Result
VResult=$Result
if [ $VResult -eq 0 ]
then
Error_Log "$(basename $CMD $PARAM3) Batch Completed Successfully"
return $VResult
else
Error_Log "$(basename $CMD $PARAM3) Failed"
return $VResult
fi
fi
}
if [[ $# -gt 0 ]]
then
echo $1|grep ksh
if [[ $? -ne 0 ]]
then
CMD=$1
else
echo $1|awk -F"." '{print $1}'|read CMD
check=1
fi
LOGIN=$UP
PARAM1=$2
PARAM3=$3
PARAM4=$4
PARAM5=$5
PARAM6=$6
PARAM7=$7
MMBIN=$MMHOME/oracle/proc/bin
SHOME=/home/rmsbatch/autoscript
echo " Shell Started the Command :" ${CMD}
echo " Parameters Passed are :" $*
echo " MM Home Directory :" $MMHOME
RunBatch
else
echo "##############################################################################################################################"
echo "# Not Enough Parameter Passed Or Usage of Parameter is not Proper"
echo "# value to be Passed to the Current Shell is : " $#
echo "# Command being executed is : " $CMD
echo "# Usage of current command is given below "
echo ""
echo "" `$MMHOME/oracle/proc/bin/$1`
echo "##############################################################################################################################"
return 99
fi
autorms.ksh is probably a shell script that takes 3 parameters...
the first of which looks to be another script (dc_load_main.ksh) but it is only a guess and not necessarily the case
the second is -q which could mean anything
the third is probably another file but you cannot tell what the file should contain as extensions are fairly arbitrary and not enforced in Unix.
In short, you need to read autorms.ksh to know anything at all.