LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-13-2005, 09:15 AM   #1
jonlake
Member
 
Registered: Apr 2004
Distribution: Slackware 11.0, Gentoo
Posts: 252

Rep: Reputation: 31
bash script


#!/bin/bash
#check dns backups
Code:
#!/bin/bash
#check dns backups

gdate=`date | awk '{print $2,$3;}'`
tmp="/apps/backups/complete"
cd /apps/backups/dnsone
for dir in `ls /apps/backups/dnsone | grep 1`
do
  cd /apps/backups/dnsone/$dir
  for file in `ls -l | grep $gdate | awk '{print $9;}'`
  do
    size=`ls -l | grep $file | awk '{print $5;}'`
    date=`ls -l | grep $file | awk '{print $6,$7;}'`
    echo "$file was backed up to /apps/backups/dnsone$dir/$file on $date. The file size is $size" >> $tmp
  done
done
Code:
# cd /apps/backups/dnsone
# ls | grep 1
10-10-1-50
10-128-133-14
10-128-5-14
10-128-5-42
10-128-5-43
10-4-0-149
10-5-0-1
When I run this, I get
Code:
# ./dns.sh
grep: can't open 13
grep: can't open 13
grep: can't open 13
grep: can't open 13
grep: can't open 13
grep: can't open 13
grep: can't open 13
I know that it is trying to run
Code:
grep May 13
when I want it to run
Code:
grep "May 13"
I know it works with the quotes because I have substituted them for the variable.
I tried
Code:
gdate=\"`date | awk '{print $2,$3;}'`\"
, and when I echo $gdate it gives me "May 13", so I thought that should work, but it gives me
Code:
grep: can't open 13"
grep: can't open 13"
grep: can't open 13"
grep: can't open 13"
grep: can't open 13"
grep: can't open 13"
grep: can't open 13"
 
Old 05-13-2005, 09:18 AM   #2
trevelluk
Member
 
Registered: Nov 2003
Location: Bristol, UK
Distribution: Debian Lenny, Gentoo (at work)
Posts: 388

Rep: Reputation: 32
Try using grep "$gdate"
 
Old 05-13-2005, 09:27 AM   #3
jonlake
Member
 
Registered: Apr 2004
Distribution: Slackware 11.0, Gentoo
Posts: 252

Original Poster
Rep: Reputation: 31
Thank you, I am an idiot. I tried that before, but it didn't work. Now I realize why it didn't work. The backups run at night and it is looking for the files that will be there afterwards, the files aren't currently there.

Thanks,

Jon
 
Old 05-13-2005, 09:36 AM   #4
trevelluk
Member
 
Registered: Nov 2003
Location: Bristol, UK
Distribution: Debian Lenny, Gentoo (at work)
Posts: 388

Rep: Reputation: 32
No problem. I've made plenty of mistakes like that before.
 
  


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
Bash Script zaicheke Programming 3 11-07-2004 06:32 PM
bash script how to? Lleb_KCir Programming 11 05-21-2004 07:03 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
bash script - incrementing a filename in a script tslinux Programming 10 08-05-2003 11:58 PM
bash script prob: how can i tell the script that a 'dd' has finished? Frustin Linux - General 2 04-02-2003 05:34 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:12 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
Open Source Consulting | Domain Registration