LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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, 10:39 AM   #1
hruday
Member
 
Registered: Jun 2015
Posts: 72

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, 12:51 PM   #2
procfs
Member
 
Registered: Jan 2006
Location: Sri Lanka
Posts: 592

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 01:01 PM.
 
Old 06-30-2015, 01:05 PM   #3
hruday
Member
 
Registered: Jun 2015
Posts: 72

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

Rep: Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524
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, 02:10 PM   #5
linom
Member
 
Registered: May 2015
Distribution: Debian, CentOS,Redhat, Fedora, Ubuntu
Posts: 57

Rep: Reputation: 10
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, 02:47 PM   #6
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Xubuntu, Manjaro
Posts: 745
Blog Entries: 3

Rep: Reputation: 347Reputation: 347Reputation: 347Reputation: 347
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, 02:59 PM   #7
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
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


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


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