LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-07-2009, 01:54 PM   #1
watcher69b
Member
 
Registered: Nov 2007
Location: /home/watcher69b
Distribution: RH, Fedora & CentOS
Posts: 544

Rep: Reputation: 40
append file name


I know similar questions have been asked before but I cannot seem to get it to work.

I have a file file.something.nhMMYY that i need to ftp
(MMYY being Month and Year)

I want to add something into the script to auto-magically insert the MMYY

I can get the date format by using
Quote:
date '+%m%d%y'

Here is the part of the script that does work
Quote:
#!/bin/sh
HOST='169.1.691.991'
USER='watcher69b'
PASSWD='linuxquestions'
FILE=‘file.something.nhmmyy’

ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
put $FILE
quit
END_SCRIPT
exit 0
Any help would be appreciated. Thanks!
 
Old 10-07-2009, 02:06 PM   #2
centosboy
Senior Member
 
Registered: May 2009
Location: london
Distribution: centos5
Posts: 1,137

Rep: Reputation: 116Reputation: 116
Quote:
Originally Posted by watcher69b View Post
I know similar questions have been asked before but I cannot seem to get it to work.

I have a file file.something.nhMMYY that i need to ftp
(MMYY being Month and Year)

I want to add something into the script to auto-magically insert the MMYY

I can get the date format by using



Here is the part of the script that does work


Any help would be appreciated. Thanks!

actually i dont think the answer i gave before is what you are looking for?
so you want a file created with the date appended? or you need to automatically include a file named with a certain date?

Last edited by centosboy; 10-07-2009 at 02:44 PM.
 
Old 10-07-2009, 06:05 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,374

Rep: Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383
Code:
d=`date '+%m%y`
f=file.something.nh
nf=${f}${d}
echo $nf
 
Old 10-08-2009, 04:24 AM   #4
watcher69b
Member
 
Registered: Nov 2007
Location: /home/watcher69b
Distribution: RH, Fedora & CentOS
Posts: 544

Original Poster
Rep: Reputation: 40
Nice thank you very much! It worked like a dream.
final code for anyone else with the same problem was:

#!/bin/sh
HOST='169.1.691.991'
USER='watcher69b'
PASSWD='linuxquestions'
d=`date '+%m%y'`
f=file.something.nh
nf=${f}${d}
echo $nf
FILE=$nf

ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
put $FILE
quit
END_SCRIPT
exit 0
 
Old 10-08-2009, 06:29 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,374

Rep: Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383
The short var names and echo are just for illustrative purposes (and because I'm lazy ).
I recommend you use more meaningful names in real code. You can assign the generated name immediately to the ultimate var (FILE), no need to use an intermediate (nf).
 
Old 10-08-2009, 07:01 PM   #6
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
You may have a problem with your script.

If the original file is file1 and exists, the ftp command can have a second argument:
put ${filename} ${filename}-${date}

In your script, you added the date to the file's name and tried to put that. That might create an empty file on the ftp server.
 
Old 10-09-2009, 04:50 AM   #7
watcher69b
Member
 
Registered: Nov 2007
Location: /home/watcher69b
Distribution: RH, Fedora & CentOS
Posts: 544

Original Poster
Rep: Reputation: 40
the put command was a typo. I am actually trying to download the file on a monthly basis.
I am hopeful though I have not yet had a chance to test yet.
 
Old 10-21-2009, 06:32 PM   #8
watcher69b
Member
 
Registered: Nov 2007
Location: /home/watcher69b
Distribution: RH, Fedora & CentOS
Posts: 544

Original Poster
Rep: Reputation: 40
Quote:
Originally Posted by watcher69b View Post
the put command was a typo. I am actually trying to download the file on a monthly basis.
I am hopeful though I have not yet had a chance to test yet.
I tested the script Im 99% there.
problem is that the file name on the remote system is 'filenameMMYY'
(note the single quotes)
the script displays the filenameMMYY but does not have the single quotes.

any ideas on adding those dam quotes to the script?
 
Old 10-21-2009, 07:31 PM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,374

Rep: Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383
No system should be creating a filename that actually has quotes in it. Are you really sure that's not just a displaying issue?
If(!) it really has quotes, that needs fixing; its going to cause all sorts of issues, as you've discovered.
If you have to live with quotes (yuck!), try backslash to escape them.

\'name\'
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to append contents of one file to another existing file amit_pansuria Programming 1 11-17-2008 10:01 AM
Append file ust Linux - Newbie 2 11-06-2008 09:51 PM
how to append columns form a column file in another file adam_blackice Programming 4 09-17-2007 11:33 PM
> writes a new file, how to append? luwigie Linux - General 1 08-26-2004 08:42 PM
append to file d-rez Linux - Newbie 2 06-20-2002 04:55 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration