nohup not logging output in a subshell

Debi

New Member
Credits
0
I am trying to capture the bytes transferred in a ftp shell. It will be used to compare to the source file sent.
The shell will be used by MANY other shells and run on different days.

1. Run with nohup like:
nohup ./ftp.sh &
dest_bytes=""
But the Lftp works and the file was sent successfully
NO results in the $LFTP_LOG therefore cannot capture bytes transferred

2. run with without nohup like:
./calling.sh &
dest_bytes=20
Lftp works and the file was sent successfully
cat $LFTP_LOG
20 bytes transferred

Here are the shells scripts. Please note, the final shell will have much more code. Reduced for this purpose of showing the concept of what I am trying to accomplish.

**********
calling.sh
**********
#== Source the script so it is part of the main process==#
. ftp.sh ARG1 ARG2
echo "Back from ftp.sh with lftp_return = $lftp_return"
if (($lftp_return != 0))
then
echo "FAILED - exiting with $lftp_return"
else
echo "SUCCESS - exiting with $lftp_return"
fi

**********
ftp.sh
**********
** some arguments in the lftp come from NETRC. Code not included here

SRC_DIR=$1
FILE=$2
LFTP_LOG=${MYDIR}/${FILE}.log

lftp -e "open -u $USER,$PASSWD $DEST_MACHINE;cd $SRC_DIR;put ${FILE};bye" > $LFTP_LOG
lftp_return=$?;export lftp_return

dest_bytes=`cat $LFTP_LOG | cut -f1 -d' '`
 


JasKinasis

Well-Known Member
Credits
1,193
The most obvious thing I can see is your SRC_DIR variable is set to $1, but in your definition of LFTP_LOG You're using MY_DIR for the path to the file..... Surely that should be SRC_DIR there.
MY_DIR is undefined, so the path to the file will be incorrect...... Perhaps that's why your log isn't getting any output?
 

Debi

New Member
Credits
0
The most obvious thing I can see is your SRC_DIR variable is set to $1, but in your definition of LFTP_LOG You're using MY_DIR for the path to the file..... Surely that should be SRC_DIR there.
MY_DIR is undefined, so the path to the file will be incorrect...... Perhaps that's why your log isn't getting any output?
Hi JasKinasis -
SRC_DIR = $1 as the calling script passes it.
calling.sh:
. ftp.sh ARG1 ARG2

ftp.sh:
SRC_DIR=$1 ===> is ARG1 from calling.sh
FILE=$2 ===> is ARG2 from calling.sh
LFTP_LOG=${MYDIR}/${FILE}.log ===> MY_DIR is an environment variable on my system.

The LFTP_LOG gets created but with NO data in it if I run with nohup.
Without nohup, the log file is populated with the bytes transferred.

I am wondering if I need to execute the ftp.sh differently. I have tried that with nohup as well, but still no results. I need to source it so the echo's and variables set in ftp.sh come back to calling.sh
 


Members online


Top