After continuing with your solution, why don't you use ssh to list the file and use scp to copy it to the localhost?
Code:
# To list
echo "ls -l /remote/file/path/remote_file_name.csv*.gz" | ssh -C -T -l <User>
# To get the file
scp <User>@<Host>:<FileFromAbove> <LocalPath>
Oh no! I cannot change the way the FTPing is done in the script.....it's already in Production env and because of some environment issues we had to fix a bit here and there.
So I cannot change from "sftp" to "ssh" & "scp" sorry! But can tweak few unix commands to work this out!
If I understood what you want, you can use both to solve your problem.
Something like:
Code:
fetch_file=`sftp -b <batch file> user@password`
echo fetch_file_succ=$?
if [ ${fetch_file_succ} -ne 0 ]
then
echo "SFTP Failed!"
exit 1
fi
File_Name_Path=`echo $fetch_file | sed 's/sftp>//g' | awk '{print $NF}'`
File_Name=`basename $File_Name_Path`
echo $File_Name
But, you are saying that you cannot trust sftp's return code.
Can you post the error SFTP is returning to you?
In the past, all my routines were based on FTP, but I could not trust on the return code, so I redirected its output to a file and did some validations on it and that's why I went to scp.
I had some sftp issues, that, even when the transfer was ok, it returned an error code != 0, just because I issued a mkdir inside the batch file, and the directory I was creating already exist in the remote host.
Hey felipe,
I was able to solve my problem by doing the below:
Code:
original code:
---------------
fetch_file=`sftp -b <batch file> user@password` 2>>$logFile
I changed it to
----------------
fetch_file=`sftp -b <batch file> user@password 2>>$logFile`
So that it captured non-zero exit status. I don't know what was happening but with original code it always use to return 0 (success)
Hi All,
I want to run multiple sql queries and store the data in variable but i want to use sql command only once. Is there a way without running sql command twice and storing.Please advise.
Eg :
Select 'Query 1 output' from dual;
Select 'Query 2 output' from dual;
I want to... (3 Replies)
I have a below syntax its working fine...
var12=$(ps -ef | grep apache | awk '{print $2,$4}')
Im getting expected output as below:
printf "%b\n" "${VAR12}"
dell 123
dell 456
dell 457
Now I wrote a while loop.. the output of VAR12 should be passed as input parameters to while loop and results... (5 Replies)
I'm working on a script in which gives certain details in its output depending on user-specified options. So, what I'd like to do is something like:
if
then
awkcmd='some_awk_command'
else
awkcmd='some_other_awk_command'
fi
Then, later in the script, we'd do something like:
... (5 Replies)
Hi,
My aim is to get the md5 hash of a file and store it in a variable.
var1="md5sum file1"
$var1
The above outputs fine but also contains the filename, so somthing like this 243ASsf25 file1
i just need to get the first part and put it into a variable.
var1="md5sum file1"... (5 Replies)
Hi all,
I am new to Linux/shell scripting having moderate knowledge.
In my script, I need to get execution time of a command (say 'ls') in mili seconds level. For this i tried using "time" command to retrieve the total execution time in milli seconds. But, the problem is that, how to save... (9 Replies)
Hi all,
I m new to this forum.
I ma facing onei issue.
I have something like this:
length= wc -l < b2| awk '{print $1}'
where b2 is filename having detauls like:
cat b2
abc1
abc4
xyc3
sbdghf4
but when I do echo "$length" it displays nothing
Also I am using awk to overcome... (4 Replies)
Hi Everyone,
I have a code which requires to be stored in different variables and I am achiving it like this.
HOST=`echo $RMP | cut -f2 -d:`
NAME=`echo $RMP | cut -f3 -d:`
DIR=`echo $RMP | cut -f4 -d:`
TYPE=`echo $RMP | cut -f5 -d:`
Is there any other way of storing value... (2 Replies)
The following program takes two command line arguments.
I want the second argument (fileCount) to be stored/printed as a int value. I tried my best to typecast the char to int (check the printf statement at last) but is not working...the output is some junk value.
This program is in its... (3 Replies)
how would i go about storing this command in a variable
echo "$LINE" | awk -F"|" '{print $1"|"$2"|"$3"}'
i have tried FOO = ${command up there} but receive the error FOO: not found
aswell as a couple of other attempt but no luck (2 Replies)
For whatever reason I cant seem to fix my syntax to do the following. I want to run a grep and count how many instances come up and store that number in a variable but I keep erroring out. Here's my code in bash:
number=grep blah file.txt | wc -l (1 Reply)