I created below script to take some backup.When i run it locally or by copying it to remote machine it is running fine.
But when i ran it like:
ssh asuser@isp2876 "bash -s" -- < AdvanceLog.sh
or
ssh asuser@isp2876 "bash -s" < AdvanceLog.sh
Gives Below output::Which is strange to me::
+ export JAVA_HOME=/usr/lib/java/jre
+ JAVA_HOME=/usr/lib/java/jre
+ export PATH=/usr/dialogic//bin:/home/as/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/usr/lib/mit/bin:/usr/lib/mit/sbin:/opt/dell/srvadmin/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/share/ant:/opt/sdm/jdk1.6.0_18/bin:.:/usr/share/ant/bin:/usr/lib/java/jre/bin:.
+ PATH=/usr/dialogic//bin:/home/as/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/usr/lib/mit/bin:/usr/lib/mit/sbin:/opt/dell/srvadmin/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/share/ant:/opt/sdm/jdk1.6.0_18/bin:.:/usr/share/ant/bin:/usr/lib/java/jre/bin:.
+ Application_logs=/h/silverstream/logs
=======================================
Please enter the Incident number
=======================================
+ Server_logs=/apps/appserver/JBossEnterprisePlatform-4.3.0.GA/jboss-as/server/HwServer/log
+ echo -e '=======================================\nPlease enter the Incident number \n======================================='
+ sleep 5
12+ read incident
+ mkdir Advance_Logs_cd /h/newstuff
mkdir: cannot create directory `Advance_Logs_cd': File exists
mkdir: cannot create directory `/h/newstuff': File exists
+ All='/h/newstuff/Advance_Logs_cd /h/newstuff'
su - asuser
asadmin
+ echo 'su - asuser'
+ echo asadmin
+ cd /apps/appserver/JBossEnterprisePlatform-4.3.0.GA/jboss-as/server/HwServer/log
+ cp server.log server_bk.log
cp: cannot stat `server.log': No such file or directory
+ mv /apps/appserver/JBossEnterprisePlatform-4.3.0.GA/jboss-as/server/HwServer/log/server_bk.log /h/newstuff/Advance_Logs_cd /h/newstuff
mv: cannot stat `/apps/appserver/JBossEnterprisePlatform-4.3.0.GA/jboss-as/server/HwServer/log/server_bk.log': No such file or directory
mv: cannot stat `/h/newstuff/Advance_Logs_cd': No such file or directory
+ ps -ef
+ grep HwServer
+ grep java
+ awk '{print $2}'
++ cat jids.txt
+ for i in '$( cat jids.txt)'
+ jmap -dump:file=heap_dump 29482
13Dumping heap to /apps/appserver/JBossEnterprisePlatform-4.3.0.GA/jboss-as/server/HwServer/log/heap_dump ...
Heap dump file created
+ mv heap_dump heap_dump_29482
+ chmod 777 heap_dump_29482
+ mv /apps/appserver/JBossEnterprisePlatform-4.3.0.GA/jboss-as/server/HwServer/log/heap_dump_29482 /h/newstuff/Advance_Logs_cd /h/newstuff
mv: cannot stat `/h/newstuff/Advance_Logs_cd': No such file or directory
+ jstack -l 29482
+ chmod 777 Thread_dump_29482.txt
+ mv /apps/appserver/JBossEnterprisePlatform-4.3.0.GA/jboss-as/server/HwServer/log/Thread_dump_29482.txt /h/newstuff/Advance_Logs_cd /h/newstuff
mv: cannot stat `/h/newstuff/Advance_Logs_cd': No such file or directory
+ cd /h/silverstream/logs
+ cp allLogs.log allLogs_bk.log
cp: cannot stat `allLogs.log': No such file or directory
+ mv /h/silverstream/logs/allLogs_bk.log /h/newstuff/Advance_Logs_cd /h/newstuff
mv: cannot stat `/h/silverstream/logs/allLogs_bk.log': No such file or directory
mv: cannot stat `/h/newstuff/Advance_Logs_cd': No such file or directory
+ cd /h/newstuff
+ tar -czvf /h/newstuff/Advance_Logs_cd /h/newstuff.tar.gz /h/newstuff/Advance_Logs_cd /h/newstuff
tar: Removing leading `/' from member names
tar: /h/newstuff.tar.gz: Cannot stat: No such file or directory
/h/newstuff/Advance_Logs_cd
/h/newstuff/
/h/newstuff/2384/
/h/newstuff/2384/linux_dbspace_setup.ksh
tar: /h/newstuff/2384/ifx099.arc: Cannot open: Permission denied
/h/newstuff/Thread_dump_29482.txt
/h/newstuff/heap_dump_29482
/h/newstuff/Advance_Logs_cd
tar: Removing leading `/' from hard link targets
tar: Exiting with failure status due to previous errors
+ rm -rf Advance_Logs_cd /h/newstuff
rm: cannot remove `/h/newstuff/2384/linux_dbspace_setup.ksh': Permission denied
rm: cannot remove `/h/newstuff/2384/ifx099.arc': Permission denied
Script::
#!/bin/bash
set -x
export JAVA_HOME=/usr/lib/java/jre
#export ANT_HOME=/users/pikapoor/ant1.8
export PATH=$PATH:$ANT_HOME/bin:$JAVA_HOME/bin:.
Application_logs=/h/silverstream/logs
Server_logs=/apps/appserver/JBossEnterprisePlatform-4.3.0.GA/jboss-as/server/HwServer/log
echo -e "=======================================\nPlease enter the Incident number \n======================================="
sleep 5
read incident
cd /h/newstuff
mkdir Advance_Logs_$incident
All=/h/newstuff/Advance_Logs_$incident
echo "su - asuser"
echo "asadmin"
cd $Server_logs
cp server.log server_bk.log
mv /apps/appserver/JBossEnterprisePlatform-4.3.0.GA/jboss-as/server/HwServer/log/server_bk.log /h/newstuff/Advance_Logs_$incident
ps -ef | grep java | grep HwServer | awk '{print $2}' > jids.txt
for i in $( cat jids.txt)
do
jmap -dump:file='heap_dump' $i
mv heap_dump heap_dump_$i
chmod 777 heap_dump_$i
mv /apps/appserver/JBossEnterprisePlatform-4.3.0.GA/jboss-as/server/HwServer/log/heap_dump_$i /h/newstuff/Advance_Logs_$incident
jstack -l $i > Thread_dump_$i.txt
chmod 777 Thread_dump_$i.txt
mv /apps/appserver/JBossEnterprisePlatform-4.3.0.GA/jboss-as/server/HwServer/log/Thread_dump_$i.txt /h/newstuff/Advance_Logs_$incident
done
cd $Application_logs
cp allLogs.log allLogs_bk.log
mv /h/silverstream/logs/allLogs_bk.log /h/newstuff/Advance_Logs_$incident
cd /h/newstuff
tar -czvf /h/newstuff/Advance_Logs_$incident.tar.gz /h/newstuff/Advance_Logs_$incident
rm -rf Advance_Logs_$incident
I am not getting any clue on why it is not running as expected when trying to run remotely without copying it.
Please suggest anybody . It would be great to me.Thanks in advance.