Link to home
Start Free TrialLog in
Avatar of sunhux
sunhux

asked on

value of variables in Shell script became null after sftp batch command : Urgent


I'm writing sftp Shell scripts (in -b batch mode) but seems like after
sftp codes, the value of the variables (in particular FILE_NAME )
was reset to null (or empty).

Attached the scripts, where scr1.sh will call scr2.sh

I've tried to export the variables (as shown in the script) but no joy.
I don't have this problem previously when this script was using 'ftp'
(but I'm now required to convert it to sftp)

The outputs I got after running "ksh -v scr1.sh " :

Couldn't stat remote file: No such file or directory
Couldn't delete file: No such file or directory
Invalid command.
Couldn't stat remote file: No such file or directory
Couldn't delete file: No such file or directory
-rw-------  1 root root 34 Oct  5 11:56 /appl/career/dataload/in/sftp_xxo_acknowledge.dat.md5
/appl/career/dataload/in/.md5
dos2unix: converting file /appl/career/dataload/in/.md5 to UNIX format ... <==$FILE_NAME is null !
dos2unix: problems converting file /appl/career/dataload/in/.md5            <==$FILE_NAME is null !



I'm on RHES 4.6
sftpVarnullScr3.txt
ASKER CERTIFIED SOLUTION
Avatar of simon3270
simon3270
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sunhux
sunhux

ASKER


Thanks, will try that in a moment when I reached office.

Btw, is the syntax   echo "-quit"  Ok?

  [
  ...
  echo "-quit"
  } sftp -b ...


Avatar of sunhux

ASKER


Hurray, both yr suggestions works
Avatar of sunhux

ASKER


> is designed to process multiple files (otherwise you wouldn't need the "for FILENAME"
>  loops at all.  This means that $3 passed into scr2.sh may have spaces in it

Yes, that's right; it may have multiple files separated by a space between the files.
But I thought scr1.sh already has double quotes when passing to scr2,sh ie
  "sftp_xxo_acknowledge1.dat sftp_xxo_acknowledge2.dat"
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sunhux

ASKER

excellent