Operating System - Linux
1827791 Members
2719 Online
109969 Solutions
New Discussion

circumstances in which relative path impact shell script

 
monu_1
Regular Advisor

circumstances in which relative path impact shell script

Hi Guru,

Ive written a script, but it seems sometime(not known) could not working. From console log i relaised it is sometimg relative path is impacting..also i never relaised this problem in develpoment phase. Here is code snippet.

=========
for z in `seq $NO_PAYLOADS`; do
FROM_PAYLOAD=${PAYLOD_IPADDR[$[z-1]]}
mkdir -p /var/log/payload_syslogs
cd /var/log/payload_syslogs
mkdir -p payload_$z
cd payload_$z
echo "Collecting syslog,dmesg,fund_com_log from $FROM_PAYLOAD"
/etc/ncs/ncs_collect_payload_syslog $FROM_PAYLOAD >>$COLLECT_LOG 2>&1
cd ../
SLOT_NO=`cat payload_$z/node_id` #problem happen here
mv payload_$z payload_$SLOT_NO
tar zcvmf payload_$SLOT_NO.tgz payload_$SLOT_NO
rm -rf payload_$SLOT_NO
done
==========

Could you please let me know in which circumstances this relative path (as well cd ../) would not work?

BR/MKS

Note: Attched is console error print.

1 REPLY 1
Matti_Kurkela
Honored Contributor

Re: circumstances in which relative path impact shell script

The use of relative paths and "cd ../" looks OK to me.

The error message says pretty clearly that the file "/var/log/payload_syslogs/payload_1/node_id" does not exist.

Because your script creates the payload_1 sub-directory, the node_id file cannot pre-exist. Should the /etc/ncs/ncs_collect_payload_syslog command create that file? *Does* it create the file in fact?

Your script redirects the error messages of the ncs_collect_payload_syslog command to the file named by the variable $COLLECT_LOG. What's in that file? Any informative error messages?

MK
MK