Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

put on hold as too broad by Jeff Schaller, sam, Michael Kjörling, Archemar, mdpc 2 days ago

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
Can you simplify this down to a smaller, more-easily reproducible error? Also, there are several errors; which are you concerned about? – Jeff Schaller 2 days ago

Not sure if this is what you're looking for, but just in case...

How can I execute local script on remote machine and include arguments?

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.