1

I need to first get the data a file was uploaded to the sftp server on, then check whether it was today's date and if so download it else echo "File not found". I would like to do all this using a bash script. This is what I have so far:

SFTP> cd test
SFTP> get myfile* 
SFTP> exit 

today=`date +%Y%m%d`
ls -lt | less |head 1 | awk '{print $7,$8,$9}' > $filedate
if ($filedate == $today)
    echo "Today's file"
else 
    echo "Today's file not found"
fi

Using the script above, I am always getting "Today's file not found" even if the file has today's date.

  • Please consider expanding your question with relevant information such as what you tried and where you are stuck. As of now, this seems like a copy pasted version of a homework question. – Ramesh Nov 6 '14 at 17:37
  • A Question (as on this site) should normally have a question: i.e. a sentence ending in a question mark (as is custom in the English language that we use here). What is your question? What have you tried that is not working? What was the (incorrect) output of what you tried. What did you expect? – Anthon Nov 6 '14 at 17:40
  • I won't Downvote this as you've already been penalized, but this sure sounds like Homework – eyoung100 Nov 6 '14 at 17:43
  • 1
    Hi user_tmo. It's really hard to tell what exactly you are asking, here. Please edit your question such that the question shows what you have tried, and asks a specific question. If English isn't your first language, then don't worry too much about grammar and spelling; rather, focus on making the question as clear as possible. (It certainly won't hurt if you also pay attention to spelling and grammar, but we prefer clear but slightly incorrect linguistically, over unclear but perfectly written. If the intent is clear, someone else can always come in and fix the language problems.) – a CVn Nov 6 '14 at 18:29
  • 1
    Does sftp support the "ls -l" command? If so, you can get file data BEFORE downloading it. – barrycarter Nov 6 '14 at 21:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.