I'm getting an error while running this script. Need help.
set -x verbose #echo on
clear #clear the screen
USERNAME="bbb"
PASSWORD="password"
SERVER="192.168.1.100"
WAIT_TIME=300
FILE_PATH="/home/users/xxx/MMM" # local directory to pickup *.dat file
REMOTE_PATH="/Drop_off/xxx/yyy" # remote server directory to upload file
#Process files
for file in $FILE_PATH/*.dat
do
echo "Processing $file ..."
# take action on each file. f store current file name
./UFTFTP_SecondScript $file
echo "Seconds until next uploadls : $WAIT_TIME"
for (( x=0; x<$WAIT_TIME"; x++ ))
do
echo "Sleeping for " $x
sleep 1
done
done
-----------UFTFTP_SecondScript------------
#!/bin/sh
set -x verbose #echo on
#CURRENT PROCESSING FILE: 1
#USERNAME: 2
#PASSWORD: 3
#SERVER: 4
#FILE_PATH: 5
#REMOTE_PATH: 6
#login to remote server
ftp -n -i $4
<<END_INPUT
user $2 $3
cd $6
mput $5/$1
quit
END_INPUT
I noticed that I wasn't passing all parameters but I'm still having the same issue.
USERNAME="bbb"
PASSWORD="password"
SERVER="192.168.1.100"
WAIT_TIME=300
FILE_PATH="/home/users/xxx/MMM" # local directory to pickup *.dat file
REMOTE_PATH="/Drop_off/xxx/yyy" # remote server directory to upload file
#Process files
for file in $FILE_PATH/*.dat
do
echo "Processing $file ..."
# take action on each file. f store current file name
./UFTFTP_SecondScript $file $USERNAME $PASSWORD $SERVER $FILE_PATH $REMOTE_PATH
echo "Seconds until next uploadls : $WAIT_TIME"
for (( x=0; x<$WAIT_TIME; x++ ))
do
echo "Sleeping for " $x
sleep 1
done
done
---------- Post updated at 03:11 PM ---------- Previous update was at 03:09 PM ----------
---------- Post updated at 03:56 PM ---------- Previous update was at 03:16 PM ----------
I tried with your loop and it worked.
#Process files
for file in $FILE_PATH/*.dat
do
echo "Processing $file ..."
# take action on each file. f store current file name
./UFTFTP_SecondScript.sh $file $USERNAME $PASSWORD $SERVER $FILE_PATH $REMOTE_PATH
echo "Seconds until next upload: $WAIT_TIME"
#for (( x=0; x<$WAIT_TIME; x++ ))
x=0
while [$x -lt $WAIT_TIME];
do
echo "Sleeping for $x"
sleep 1
x='expr $x + 1'
done
done
Now the problem is connecting to the ftp.
+ ftp -n -i
Not connected.
Not connected.
Not connected.
+ echo Seconds until next upload: 300
Seconds until next upload: 300
+ x=0
+ [0 -lt 300]
./UploadFileToFtp.sh: 1: [0: not found
It looks like you messed up a [ ] type of comparison statement, but there's nothing like that in the ftp script you posted, could you post it in complete?
Most of the recent error messages come from this line:
There must be a space character after a [ and before a ]. The semicolon at the end of the line is not required at all.
while [ $x -lt $WAIT_TIME ]
The FTP script has some issues: The << "Start of Here Document" is misplaced. Also why "mput" when the calling script logic is for one file? We need to use "lcd" to change local directory. Don't indent "Here Documents" - it will bite you in the hand.
#!/bin/sh
set -x verbose #echo on
#CURRENT PROCESSING FILE: 1
#USERNAME: 2
#PASSWORD: 3
#SERVER: 4
#FILE_PATH: 5
#REMOTE_PATH: 6
#login to remote server
ftp -n -i $4 <<END_INPUT
user $2 $3
cd $6
lcd $5
put $1
quit
END_INPUT
In post #4 you were asked what is your shell and what is your system. Please post (blotting anything confidential with X's):
#!/bin/bash
set -x verbose #echo on
clear #clear the screen
USERNAME="xxxx"
PASSWORD="xxxx"
SERVER="192.168.225.1"
WAIT_TIME=300
FILE_PATH="/home/user/Desktop/XXX" # local directory to pickup *.dat file
REMOTE_PATH="/Drop_off/Region_3_prod/XXX" # remote server directory to upload backup
#Process files
for file in $FILE_PATH/*.dat
do
# take action on each file. [file] store current file name
./UFTFTP_SecondScript $file $USERNAME $PASSWORD $SERVER $REMOTE_PATH
echo "Seconds until next upload: $WAIT_TIME"
x=0
while [ $x -lt $WAIT_TIME ]
do
echo "Sleeping for $x..."
sleep 1
x='expr $x + 1'
done
done
-----SecondFile-----
#!/bin/bash
set -x verbose #echo on
#file: 1
#USERNAME: 2
#PASSWORD: 3
#SERVER: 4
#REMOTE_PATH: 5
#login to remote server
echo "Processing file $1..."
ftp -n -i $4 <<END_INPUT
user $2 $3
cd $5
put $1
quit
END_INPUT
---------- Post updated at 10:13 AM ---------- Previous update was at 10:10 AM ----------
+ clear
+ USERNAME=XXX
+ PASSWORD=XXX
+ SERVER=192.168.225.1
+ WAIT_TIME=300
+ FILE_PATH=/home/user/Desktop/XXX
+ REMOTE_PATH=/Drop_off/Region_3_prod/XXX
+ for file in '$FILE_PATH/.dat'
+ ./UFTFTP_SecondScript '/home/user/Desktop/XXX/.dat' XXX XXX 192.168.225.1 /Drop_off/Region_3_prod/XXX
./UploadFileToFtp.sh: line 25: ./UFTFTP_SecondScript: No such file or directory
+ echo 'Seconds until next upload: 300'
Seconds until next upload: 300
+ x=0
+ '[' 0 -lt 300 ']'
+ echo 'Sleeping for 0...'
Sleeping for 0...
+ sleep 1
+ x='expr $x + 1'
+ '[' expr '$x' + 1 -lt 300 ']'
./UploadFileToFtp.sh: line 28: [: too many arguments
In your example $1 contains a full hierarchial path name "put" defaults the "to filename" to be the same as the "from filename". Thus the full hierarchial filename is invalid on the destination system.
You need to strip the directory portion off the filename with a command such as "basename", then use both "lcd" an "cd" within the ftp script.
Something like this:
# In the script (before executing the ftp)
local_filename=`basename $1`
local_dir=`dirname $1`
remote_dir=$5
#Then in the ftp portion of the script:
lcd ${local_dir}
cd ${remote_dir}
put ${local_filename}
Starting process...
Using the following values:
Username: zzzz
Password: zzzz
Server: xxx.xxx.xxx.xxx
Wait time: 5 seconds
Remote Path: /Drop_off/Region_3_prod/EDI
Connecting to server...
Local Directory /home/user/Desktop/MMM...
Processing file EDEInmediataInboundClaims837.dat...
Local directory now /home/user/Desktop/MMM
Finihed procesing file EDEInmediataInboundClaims837.dat...
Seconds until next upload: 5
Procesing file number: 1
Connecting to server...
Local Directory /home/user/Desktop/MMM...
Processing file EDEInmediataInboundClaims837IEDIMMM20111117193200001v1-5010-50.dat...
Local directory now /home/user/Desktop/MMM
Finihed procesing file EDEInmediataInboundClaims837IEDIMMM20111117193200001v1-5010-50.dat...
Seconds until next upload: 5
Procesing file number: 2
Connecting to server...
Local Directory /home/user/Desktop/MMM...
Processing file EDEInmediataInboundClaims837IEDIPMC20111117194600001v1-5010-50.dat...
Local directory now /home/user/Desktop/MMM
Finihed procesing file EDEInmediataInboundClaims837IEDIPMC20111117194600001v1-5010-50.dat...
Seconds until next upload: 5
Procesing file number: 3
Connecting to server...
Local Directory /home/user/Desktop/MMM...
Processing file EDEInmediataInboundClaims837PEDIMMM20111117195600001v1-5010.dat...
Local directory now /home/user/Desktop/MMM
Finihed procesing file EDEInmediataInboundClaims837PEDIMMM20111117195600001v1-5010.dat...
Seconds until next upload: 5
Procesing file number: 4
Connecting to server...
Local Directory /home/user/Desktop/MMM...
Processing file EDEInmediataInboundClaims837PEDIPMC20111117194900001v1-5010-50.dat...
Local directory now /home/user/Desktop/MMM
Finihed procesing file EDEInmediataInboundClaims837PEDIPMC20111117194900001v1-5010-50.dat...
Seconds until next upload: 5
Procesing file number: 5