Hi ,
I have one main script called script1.sh which contains the cotennts below. this script wil search for the existence of files in a particular directory and if one file is finidin it wil send to another server . this is the basic functionality
the script1.sh is given below
#Al the directiory locations wil be mentinedin the first
# Trace output function
trace ()
{
if [ $TRACE ]
then
DATE=`date +"%Y-%m-%d %X"`
echo "$DATE: $1" >> $TRACEFILE
fi
}
trace "Script $0 started"
# First find all alarm files to import at start
FILES="`find $ALARM_FILES_DIR -type f`"
# Loop forever and import files
while [ true ]
do
loop=`expr $loop + 1`
# cat the files to a text file
if [ "$FILES" != "" ]
then
FILES_SORTED="`ls -rt $FILES`"
trace "Alarm files to import:\n$FILES_SORTED"
for i in $FILES_SORTED
do
cat $i>export1.txt
username=***
password=***
expect -c "
\# exp_internal 1 \# uncomment for debugging
spawn /usr/bin/scp export1.txt ***@ipaddress:/location
expect \{
"\*password:*" \{ send $password\\r\\n; interact \}
eof \{ exit \}
\}
exit
"
/export/home/netcool/rohith/script.sh
rm -rf export1.txt
echo
done
LATEST="$i"
SENDHB=false
else
trace "No new alarm files to import"
SENDHB=true
fi
trace "Latest alarm file imported: $LATEST"
#
# If the latest file sent still exists then find newer files, otherwise find all files
if [ -f "$LATEST" ]
then
FILES="`find $ALARM_FILES_DIR -newer $LATEST -type f`"
else
FILES="`find $ALARM_FILES_DIR -type f`"
fi
# Modify sleep time (in seconds) as needed below
sleep 2
done
THIS SCRIPT WIL CALL THE SECOND SCRIPT CALLED SCRIPT.SH contents given below since expect cant used inside the first script i hav given like dat in dif script i mean /usr/bin/expect -f
#!/usr/local/bin/expect -f
spawn ssh ***@ipaddrss 'location/ssh.sh'
expect "password:"
send "netcool\n"
interact
This wil call another script in server2 called ssh.sh contents are given below
#!/bin/sh
cat export1.txt >> export.txt
rm export1.txt
I need to execute all these 3 scripts in crontab for copyn the files automatically.
I am really a beginner in scripting. I know some logical mismatch may be der . PLease correct me and help me out for solving this.
REgards,
ROhith G