Problem with MV command in Shell Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with MV command in Shell Script
# 1  
Old 04-13-2009
Problem with MV command in Shell Script

Hi Guru's,

I 'm trying to execute the below given script in Unix. I am having an issue with the script. The output of the script is given below:

#!/bin/bash


File_Home="/home/essftp/Risk"

cd /home/essftp/Risk
rm -f FileList
rm -f credit_risk*

file1=`ls -lt /export/archives/datman/prod/bloomberg/credit_risk.out.gz* |awk '{print $9 "\t" $10}'|cut -f5 -d"/"|head -1`
sftp nydbrsko@eqdmnypr1<<END_SCRIPT >&FileList
cd /export/archives/datman/prod/bloomberg
ls credit_risk.out.gz*
bye
END_SCRIPT

filename=`nawk '{if($NF ~ "credit_risk.out.gz") {print $NF}}' FileList | sort -r | sed -ne '1p'`

ftp nydbrsko@eqdmnypr1<<END_SCRIPT
cd /export/archives/datman/prod/bloomberg
get $filename
bye
END_SCRIPT

echo "/home/essftp/Risk/$filename"

mv $file_name /home/essftp/Risk/credit_risk.out.gz
gunzip -f credit_risk.out.gz
chmod 777 credit_risk.out
echo "DONE"


Script Output:

/export/archives/datman/prod/bloomberg/credit_risk.out.gz*: No such file or directory
nydbrsko's Password:
nydbrsko@eqdmnypr1: unknown host or invalid literal address
Not connected.
Not connected.
/home/essftp/Risk/credit_risk.out.gz.20090412
mv: Insufficient arguments (1)
Usage: mv [-f] [-i] f1 f2
mv [-f] [-i] f1 ... fn d1
mv [-f] [-i] d1 d2
gunzip: credit_risk.out.gz: No such file or directory
chmod: WARNING: can't access credit_risk.out
DONE

The script is logging into sftp site and getting the file name. But in the end it is failing to move the file.

Can someone please look into this and explain me whats wrong am i doing here.

Thanks and Best Regards
Ranjith
# 2  
Old 04-13-2009
Use below option to debug it.
This will might help you.

#!/bin/bash -x
# 3  
Old 04-13-2009
Is there a "mv $file_name " or "mv $filename" also maybe put in the path?
# 4  
Old 04-13-2009
variable misname, giannicello.
remove the underscore in the mv file_name command to be mv filename

Code:
filename=`nawk '{
  if($NF ~ "credit_risk.out.gz") {print $NF}}' FileList | sort -r | sed -ne '1p'`

ftp nydbrsko@eqdmnypr1<<END_SCRIPT
cd /export/archives/datman/prod/bloomberg
get $filename
bye
END_SCRIPT

echo "/home/essftp/Risk/$filename"

mv $filename /home/essftp/Risk/credit_risk.out.gz

# 5  
Old 04-13-2009
oh and add this after the nawk statement:

Code:
if [ -z "$filename" ]; then
  echo no credit_risk.out.gz found.
  exit 1
fi

( could be done a little nicer with variable file name.... )
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unable to pass shell script variable to awk command in same shell script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk... (2 Replies)
Discussion started by: Ashunayak
2 Replies

2. Shell Programming and Scripting

Problem with expr command in shell script

Hi, I have used expr command to increment the date. for e.g., case 1 : echo $(date -d $(echo `expr 20010101 + 1`)) it returns Tue Jan 2 00:00:00 IST 2001 case 2: echo $(date -d $(echo `expr 20010101 - 1`)) it returns date: invalid date `20010100' please suggest me, how to... (3 Replies)
Discussion started by: nanthagopal
3 Replies

3. Shell Programming and Scripting

Problem facing command using shell

Dear Brothers! Need your help for the case where I am running one command on prompt and its giving us the correct output, but when i use the same command from shell its directs no output.:wall: the command on command prompt is ls -ltrh * | nawk '{if ($5~ '/$'M'/') print $9}' | grep -v... (1 Reply)
Discussion started by: jojo123
1 Replies

4. Shell Programming and Scripting

Problem using cut command in shell script

I'm new to shell programming, and am having a problem in a (Korn) shell program, which boils down to this: The program reads a record from an input file and then uses a series of "cut" commands to break the record into parts and assign the parts to variables. There are no delimiters in the... (2 Replies)
Discussion started by: joroca
2 Replies

5. Shell Programming and Scripting

Problem Executing Firmware Command using Shell Script

Guys, I have a script that should change one of the configuration Parameter in a http accelerator, this config change which will halt http traffic into device. So I have designed a script which should do these changes. But after executing this script, found that one of the input variable is not... (8 Replies)
Discussion started by: raghunsi
8 Replies

6. Shell Programming and Scripting

problem in exit status of the command in a shell script-FTP

Hi All, I have developed below script for FTP a file from unix machine to another machine. ftpToABC () { USER='xyz' PASSWD='abc' echo "open xx.yy.zbx.aaa user $USER $PASSWD binary echo "put $1 abc.txt" >> /home/tmp/ftp.$$ echo "quit" >> /home/tmp/ftp.$$ ftp -ivn <... (3 Replies)
Discussion started by: RSC1985
3 Replies

7. Shell Programming and Scripting

shell script problem , sudo mount command

cat test.sh sudo mount -t vfat /dev/sda7 /media/Ddrive If i double click the test.sh file and select run in terminal then the terminal prompts for password. How can i avoid typing password? Or if i double click test.sh file and select run then nothing happens. What i'm trying "Double... (3 Replies)
Discussion started by: cola
3 Replies

8. UNIX for Advanced & Expert Users

Problem with find command in C-shell

when i use the following command find / -name '*.*' -exec grep -il 'text' {} \; I can redirect the errors to /dev/null. This happens only in ksh but not in csh. the 2>/dev/null is not working in csh. Can you some one suggest an alternative for this in csh ? (3 Replies)
Discussion started by: dhanamurthy
3 Replies

9. Shell Programming and Scripting

problem with sed command in shell script.

Guys, I've a problem in the "sed" command used in my shellscripts This is the problamatic line in my shell script: sed -e 's/${line1}/${line1_m}/g' prod_hier_1234.txt > test.txt It doesn't do the job of replacing the string stored in variable 'line1' to 'line1_m'. However If I replace the... (10 Replies)
Discussion started by: bhagat.singh-j
10 Replies

10. Shell Programming and Scripting

problem executed shell command from PL/SQL

i wrote plsql procedure that executed shell command using java class my problem is that in some reason the shell command ( liks Is -l , mv ... ) are not recordnize can someone help me with that 10x Alodvg (2 Replies)
Discussion started by: alodvg
2 Replies
Login or Register to Ask a Question