LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 11-28-2015, 02:49 AM   #16
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled

Quote:
Originally Posted by hruday View Post
td=$(echo emt_bus-$(date --date "-0 month" +01-m-%y).sql)
Missing an "%" delimiter:
Code:
td=$(echo emt_bus-$(date --date "-0 month" +01-%m-%y).sql)
 
Old 11-29-2015, 08:57 AM   #17
hruday
Member
 
Registered: Jun 2015
Posts: 88

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by berndbausch View Post
Use cp -v (verbose).
What happens if you enter the exact same cp command manually?
nothing is happening. its not copying the file.
 
Old 11-29-2015, 09:22 AM   #18
hruday
Member
 
Registered: Jun 2015
Posts: 88

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Habitual View Post
Missing an "" delimiter:
Code:
td=$(echo emt_bus-$(date --date "-0 month" +01-%m-%y).sql)
yes i looked into that earlier mistake and changed it. still its not working

i tried with following commands at prompt

find ./* -type f -name "hri-01*" -exec ls {} \; ---> its working.!

but

find ./* -type f -name "hri-$(date --date "-0 month" +01-%m-%y).sql.zip" -exec ls {} \; ---> this didn't work as expected.

find ./* -type f -name "echo $(hri-$(date --date "-0 month" +01-%m-%y).sql.zip)" -exec ls {} \; --> this also didn't work

Last edited by hruday; 11-29-2015 at 09:35 AM.
 
Old 11-29-2015, 06:24 PM   #19
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
This string:
Code:
"hri-$(date --date "-0 month" +01-m-y).sql.zip"
expands to this on my system:
Code:
hri-01-m-y.sql.zip
So, it won't work.

Last edited by berndbausch; 11-29-2015 at 06:28 PM.
 
Old 11-29-2015, 08:26 PM   #20
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by hruday View Post
yes i looked into that earlier mistake and changed it. still its not working

i tried with following commands at prompt

find ./* -type f -name "hri-01*" -exec ls {} \; ---> its working.!

but

find ./* -type f -name "hri-$(date --date "-0 month" +01-m-y).sql.zip" -exec ls {} \; ---> this didn't work as expected.

find ./* -type f -name "echo $(hri-$(date --date "-0 month" +01-m-%y).sql.zip)" -exec ls {} \; --> this also didn't work
echo is your friend.
Code:
echo hri-$(date --date "-0 month" +01-%m-%y).sql.zip
spits out
hri-01-11-15.sql.zip

touch is your friend.
Code:
touch  hri-$(date --date "-0 month" +01-%m-%y).sql.zip
hri-01-11-15.sql.zip

find is your friend:
Code:
find   hri-$(date --date "-0 month" +01-%m-%y).sql.zip
hri-01-11-15.sql.zip

Code:
find -name $(echo hri-$(date --date "-0 month" +01-%m-%y).sql.zip)
and
Code:
find -name $(echo hri-$(date --date "-0 month" +01-%m-%y).sql.zip) -exec ls {} \;
both work here.
both show
./hri-01-11-15.sql.zip

Go back to here. and use the 3 commands I gave you.

TARGET=
touch $TARGET
find

build from there.

What's not clear to me is why you insist on useless searching
Code:
find ./*
when you know where the files are at?

Code:
find /home/applications/ets/backup/ets_old_sqldumps/ -iname hri$(date -d "$(date -d month +Y-%m-1) -1 day" "+%m-%d-%Y").sql
+Y is missing an "%" operand, again.

http://www.cyberciti.biz/faq/howto-f...files-by-date/

Last edited by Habitual; 11-30-2015 at 06:19 AM.
 
Old 12-01-2015, 06:10 AM   #21
hruday
Member
 
Registered: Jun 2015
Posts: 88

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Habitual View Post
echo is your friend.
Code:
echo hri-$(date --date "-0 month" +01-%m-%y).sql.zip
spits out
hri-01-11-15.sql.zip

touch is your friend.
Code:
touch  hri-$(date --date "-0 month" +01-%m-%y).sql.zip
hri-01-11-15.sql.zip

find is your friend:
Code:
find   hri-$(date --date "-0 month" +01-%m-%y).sql.zip
hri-01-11-15.sql.zip

Code:
find -name $(echo hri-$(date --date "-0 month" +01-%m-%y).sql.zip)
and
Code:
find -name $(echo hri-$(date --date "-0 month" +01-%m-%y).sql.zip) -exec ls {} \;
both work here.
both show
./hri-01-11-15.sql.zip

Go back to here. and use the 3 commands I gave you.

TARGET=
touch $TARGET
find

build from there.

What's not clear to me is why you insist on useless searching
Code:
find ./*
when you know where the files are at?


Code:
find /home/applications/ets/backup/ets_old_sqldumps/ -iname hri$(date -d "$(date -d month +Y-%m-1) -1 day" "+%m-%d-%Y").sql
+Y is missing an "%" operand, again.

http://www.cyberciti.biz/faq/howto-f...files-by-date/

you are using "touch" command. it'll create a file. i don't want to create any file. i just want to find the files in a directory which match the pattern.
 
Old 12-01-2015, 08:38 AM   #22
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by hruday View Post
i don't want to create any file.
Who cares? You have 29 days to remove the 0 byte file.
How are you going to find what doesn't exist yet?
It is going to be overwritten anyway, right? By the backup program or utility/script?
Or is that written by someone else as well?

using the touch command today allows you to create the file in advance so you can test your find command today with it.
You're in luck, it's a new calendar month, so this becomes easier.

Your solution is
Code:
#!/bin/bash
TARGET=hri-$(date -d "$(date -d month +Y-%m-1) -1 day" "+%m-%d-%Y").sql
find /home/applications/ets/backup/ets_old_sqldumps/ -name "$TARGET"
#EOF
YOU could simply add a touch and rm in bash now to that to test my work.
Code:
TARGET=hri-$(date -d "$(date -d month +%Y-%m-1) -1 day" "+%m-%d-%Y").sql
# Create file for testing.
touch /home/applications/ets/backup/ets_old_sqldumps/hri-$(date -d "$(date -d month +%Y-%m-1) -1 day" "+%m-%d-%Y").sql
OR...
touch /home/applications/ets/backup/ets_old_sqldumps/$TARGET
find /home/applications/ets/backup/ets_old_sqldumps/ -name "$TARGET"
# Remove file after testing.
rm /home/applications/ets/backup/ets_old_sqldumps/hri-$(date -d "$(date -d month +%Y-%m-1) -1 day" "+%m-%d-%Y").sql
or
rm /home/applications/ets/backup/ets_old_sqldumps/$TARGET
Have a Great Day.

Last edited by Habitual; 12-01-2015 at 09:27 AM.
 
Old 12-02-2015, 07:09 AM   #23
hruday
Member
 
Registered: Jun 2015
Posts: 88

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Habitual View Post
Who cares? You have 29 days to remove the 0 byte file.
How are you going to find what doesn't exist yet?
It is going to be overwritten anyway, right? By the backup program or utility/script?
Or is that written by someone else as well?

using the touch command today allows you to create the file in advance so you can test your find command today with it.
You're in luck, it's a new calendar month, so this becomes easier.

Your solution is
Code:
#!/bin/bash
TARGET=hri-$(date -d "$(date -d month +Y-%m-1) -1 day" "+%m-%d-%Y").sql
find /home/applications/ets/backup/ets_old_sqldumps/ -name "$TARGET"
#EOF
YOU could simply add a touch and rm in bash now to that to test my work.
Code:
TARGET=hri-$(date -d "$(date -d month +%Y-%m-1) -1 day" "+%m-%d-%Y").sql
# Create file for testing.
touch /home/applications/ets/backup/ets_old_sqldumps/hri-$(date -d "$(date -d month +%Y-%m-1) -1 day" "+%m-%d-%Y").sql
OR...
touch /home/applications/ets/backup/ets_old_sqldumps/$TARGET
find /home/applications/ets/backup/ets_old_sqldumps/ -name "$TARGET"
# Remove file after testing.
rm /home/applications/ets/backup/ets_old_sqldumps/hri-$(date -d "$(date -d month +%Y-%m-1) -1 day" "+%m-%d-%Y").sql
or
rm /home/applications/ets/backup/ets_old_sqldumps/$TARGET
Have a Great Day.
yeah i found my error and corrected it. i managed to copy the files to other directory. now how can i upload this file to ftp server
 
Old 12-03-2015, 02:00 AM   #24
hruday
Member
 
Registered: Jun 2015
Posts: 88

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by hruday View Post
yeah i found my error and corrected it. i managed to copy the files to other directory. now how can i upload this file to ftp server
#!/bin/bash

HOST='ipaddress'
USER='username'
PASSWD='pwd'
cd ~/exp
FILE="f*.log" -----> trying to copy files starting with letter "f" with .log extension
REMOTEPATH='~/backup'

ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
cd $REMOTEPATH
put $FILE
quit
END_SCRIPT
exit 0

in "exp" directory i have created around 5 files like f1.log, f2.log, f3.log, f4.log, f5.log
but iam able to copy only one file f1.log

how to copy all files?
 
Old 12-03-2015, 02:18 AM   #25
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by hruday View Post
#!/bin/bash

HOST='ipaddress'
USER='username'
PASSWD='pwd'
cd ~/exp
FILE="f*.log" -----> trying to copy files starting with letter "f" with .log extension
REMOTEPATH='~/backup'

ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
cd $REMOTEPATH
put $FILE
quit
END_SCRIPT
exit 0

in "exp" directory i have created around 5 files like f1.log, f2.log, f3.log, f4.log, f5.log
but iam able to copy only one file f1.log

how to copy all files?
You need mput and prompt.
Or instead of prompt, use the ftp -i option.

Last edited by berndbausch; 12-03-2015 at 02:20 AM.
 
Old 12-03-2015, 06:01 AM   #26
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by hruday View Post
yeah i found my error and corrected it.
You're welcome.
 
Old 12-03-2015, 06:03 AM   #27
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by berndbausch View Post
You need mput and prompt.
Or instead of prompt, use the ftp -i option.
Nooooooo, he needs to start a new thread.
 
Old 12-03-2015, 06:14 AM   #28
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
I thought the thread title was sufficiently broad
 
Old 12-03-2015, 06:20 AM   #29
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by berndbausch View Post
I thought the thread title was sufficiently broad
OK. Where's the coffee?

I'm gonna suggest sftp for easier automation.
That's my story and I'm sticking to it!

Last edited by Habitual; 12-03-2015 at 06:22 AM.
 
Old 12-03-2015, 11:22 PM   #30
hruday
Member
 
Registered: Jun 2015
Posts: 88

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by berndbausch View Post
You need mput and prompt.
Or instead of prompt, use the ftp -i option.
ok thanx @brendbausch and @habitual

so how can i put these two tasks together?

#!/bin/bash
src=/root/exp

df=$(date --date "-`date +%d` days +1 month" +%d-%m-%y)
tf="hri-$df.sql"

find $src/* -type f -name "$tf" -exec ls {} \;

if [$? -eq 0] then

can i write the ftp script here to transfer the above file?
or what is the best way?
 
  


Reply



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
Get first day of last month and last day of last month in bash xowl Linux - Software 18 02-09-2017 09:49 AM
cron job: day of month / day of week conflict? geekpie Linux - General 2 10-21-2009 03:56 AM
Help needed to transfer list of files to FTP server, to different folders amazon Programming 1 06-26-2009 01:12 AM
OpenOffice.org Calc formula to check if day is last day of the month win32sux Linux - Software 1 01-19-2009 12:38 PM
Starting day of month, month length chrisk5527 Programming 2 03-03-2004 04:03 PM

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

All times are GMT -5. The time now is 11:06 PM.

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
Open Source Consulting | Domain Registration