简体   繁体   中英

A shell script on linux is not able to run

I am trying to run an shell script on a Linux Ububtu 12.04 LTS server. Here is my script:

#!/bin/bash
PROGRAM=./home/lab/data/setup_exp/Simulator
FILE_PART_PREFIX="/home/lab/data/pcap_partial/h_"
FILE_PART_NUM=3
RECEIVER_SIZE=4096
SENDER_SIZE=4096
BETA=0.25
UPDATE=400
MARKER=20
MODE=5
RESULT_PREFIX="/home/lab/data/setup_exp/size/size_eq4/res_"
time_part=1200
if [ ${time_part} -eq 1200 ];then
 nohup ${PROGRAM} 1 ${FILE_PART_PREFIX}${time_part}.pcap ${RECEIVER_SIZE} ${SENDER_SIZE} ${BETA} ${UPDATE} ${MARKER} ${MODE} >> ${RESULT_PREFIX}${time_part} 2>&1 &
fi
time_part=1500
if [ ${time_part} -eq 1500 ];then
nohup ${PROGRAM} 1 ${FILE_PART_PREFIX}${time_part}.pcap ${RECEIVER_SIZE} ${SENDER_SIZE} ${BETA} ${UPDATE} ${MARKER} ${MODE} >> ${RESULT_PREFIX}${time_part} 2>&1 &
fi
time_part=1900
if [ ${time_part} -eq 1900 ];then
nohup ${PROGRAM} 1 ${FILE_PART_PREFIX}${time_part}.pcap ${RECEIVER_SIZE} ${SENDER_SIZE} ${BETA} ${UPDATE} ${MARKER} ${MODE} >> ${RESULT_PREFIX}${time_part} 2>&1 &
fi

Then, These are files and sub-directory in the directory of the script above, called sizesetup.sh : Simulator size sizesetup.sh The permission of Simulator and sizesetup.sh are set to 755.

In addition,the input files of Simulator are under /home/lab/data/pcap_partial , which are named h_1200, h_1500 and h_1900.

My problem is that I used sh sizesetup.sh to run this script without any error messages popping out. However, the script was not executed (I used 'top'and 'ps' commands to check the state of the script)

This line looks suspicious to me:

PROGRAM=./home/lab/data/setup_exp/Simulator

I don't think the leading dot is to be there. You might have come from Windows and heard that on Linux in order to run a program you need to invoke it like this: ./program .

That's not technically true. The reason of that confusion is the difference in PATH handling in Windows and Linux.

On Windows when you try to execute a program the current directory is searched first regardless of current directory being listed in %PATH% environment variable.

On Linux the current directory is neither searched implicitly (as opposite to the Windows behavior) nor the current directory (that is . ) is included in the $PATH environment variable by default. Thus in order to execute a program residing in the current directory you invoke it like this: ./program , ie explicitly specifying a relative path to the executable .

./home/lab/data/setup_exp/Simulator doesn't look like a relative path (though I might be wrong for sure), thus the leading dot is not supposed to be there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM