LinuxQuestions.org
Visit Jeremy's Blog.
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 06-30-2015, 09:39 AM   #1
hruday
Member
 
Registered: Jun 2015
Posts: 88

Rep: Reputation: Disabled
executing two commands one after the other in shell script


Please look into the script

#!/bin/bash

path1="/home/backup/newlogs/logs"
path2="/home/backup/softwares/mylogs/logs/"

echo "listing files"

find $path1/server.log.* -type f -mtime +90 -exec ls -lht {} \;
sleep 3
find $path2/server.log.* -type f -mtime +90 -exec ls -lht {} \;

echo "files listed"

exit
---------------------------------------------------------------
problem is that i can list only path1 files. iam unable to list path2 files.

Can anybody please correct this script.
 
Old 06-30-2015, 11:51 AM   #2
procfs
Member
 
Registered: Jan 2006
Location: Sri Lanka
Posts: 651

Rep: Reputation: 34
Hi looks good unless there are no files to list in path 2, why don't you try below simple debugging

echo "listing files"

find $path1/server.log.* -type f -mtime +90 -exec ls -lht {} \;
sleep 3

echo "listing path 2"
find $path2/server.log.* -type f -mtime +90 -exec ls -lht {} \;

echo "files listed"

And check the file format

Last edited by procfs; 06-30-2015 at 12:01 PM.
 
Old 06-30-2015, 12:05 PM   #3
hruday
Member
 
Registered: Jun 2015
Posts: 88

Original Poster
Rep: Reputation: Disabled
U did no corrections. please correct the script.
 
Old 06-30-2015, 01:02 PM   #4
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by hruday View Post
U did no corrections. please correct the script.
In my signature is a link to my blog entry on BASH programming where I show how to do some debug steps for your scripts, My Bash Blog.

One technique is to echo variable values, or echo progress, as you are doing. Another technique is to add the line:
Code:
set -xv
near the top of your script, but after the #!/bin/sh line. This will enable verbose debugging and you'll see the progress of the script as well as more details. Give the blog a look for other recommendations.

Note that only you know the full requirements and what you're trying to achieve, and therefore you should evaluate and test with the whole variety of expected conditions that you can conceive of.

For me I would take the mtime qualifiers out at first and ensure that it performs the basic find and exec command, and then add back in the mtime qualifiers. Because a reason why it might not see any files is because there are none to see.

I'm assuming by the way that you do have a:
Code:
#!/bin/sh
line in your code?

Further, there's also a link in my signature discussing how to put your code within [code][/code] markers to have it appear properly in a post.

I ran a modified variation of your script on my testcode directory and it worked fine:
Code:
#!/bin/sh

path1="/home/myuser/testcode"
path2="/home/myuser/testcode"

echo "listing files"

find $path1/*.c -exec ls {} \;
sleep 3
find $path2/*.c -exec ls {} \;

echo "files listed"

exit
The result was:
Code:
listing files
/home/myuser/testcode/a.c
/home/myuser/testcode/array.c
/home/myuser/testcode/bright.c
/home/myuser/testcode/decode.c
    -- 3 second pause was here --
/home/myuser/testcode/a.c
/home/myuser/testcode/array.c
/home/myuser/testcode/bright.c
/home/myuser/testcode/decode.c
files listed
I also found that adding in the "-type f" and '-lht" terms cause no problems.

procfs's suggestion to add a debug statement between the first find and the second find is a good idea by the way, in fact you should add a statement before the sleep 3 and just after it to know that it's reached that second find command.

Are you saying that you never see the final "files listed" comment?
 
Old 06-30-2015, 01:10 PM   #5
linom
Member
 
Registered: May 2015
Location: India
Distribution: Debian, CentOS,Redhat, Fedora, Ubuntu
Posts: 91

Rep: Reputation: 13
Thumbs up

Hi,

Check this out...


#!/bin/bash

path1="/home/backup/newlogs/logs"
path2="/home/backup/softwares/mylogs/logs/"

echo "Listing files:-$path1"

find $path1/server.log.* -type f -mtime +90 -exec ls -lht {} \; && echo "Listing files:-$path2" && find $path2/server.log.* -type f -mtime +90 -exec ls -lht {} \;

echo "files listed"

exit


Hope this should work for you.
 
Old 06-30-2015, 01:47 PM   #6
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Quote:
Originally Posted by hruday View Post
U did no corrections. please correct the script.
Just a side note here, in my experience, if you want to get help...
- don't DEMAND other people to solve your problem for you, and
- it helps if you are polite

Best regards
 
Old 06-30-2015, 01:59 PM   #7
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Quote:
Originally Posted by hruday View Post
U did no corrections. please correct the script.
He added a print command between the two finds so you could see if the second find was simply not returning anything. It's called debugging.
 
  


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] Executing commands in the current shell, while not launching subshells Longeron Linux - Newbie 10 01-27-2013 07:55 PM
[SOLVED] Help executing shell commands in a Python script zippy4251 Programming 7 09-25-2012 11:20 AM
[SOLVED] executing shell commands in makefiles entz Programming 1 03-23-2012 11:15 PM
executing shell commands in PHP mohtasham1983 Programming 7 09-14-2007 11:04 AM
executing shell commands in c++ true_atlantis Programming 2 10-01-2004 04:53 PM

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

All times are GMT -5. The time now is 04:46 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