- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Shell script problem
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2000 02:37 AM
11-30-2000 02:37 AM
I'm trying to write a script that checks a directory, moves the files that contain data and deletes the remaining 0 length files - Below is my script that doesn't work properly:
for i in `ll /users/admin/output/ | awk '{print $9}'`
do
if [[ -s "$i" ]]
then
print $i
mv /users/admin/output/$i /users/admin/output/keep/$i
fi
done
rm /users/admin/output/late*
Could anybody point me in the right direction?? Also, could you recommend a good book that I could use to learn from (one that contains good examples etc.) Thank you in advance for any respone, they are very much appreciated.
Best Regards, Barry.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2000 02:52 AM
11-30-2000 02:52 AM
Re: Shell script problem
Try this:
for i in `ll /users/admin/output/ | awk '{print $9}'`
do
if [ -s "$i" ]
then
print $i
mv /users/admin/output/$i /users/admin/output/keep/$i
fi
done
rm /users/admin/output/late*
Double brackets are not needed here, but be sure that there is a space between the opening bracket and the test flag, and before the closing bracket.
ll may be replace by a 'ls -1', more effective, and avoiding an 'awk' pipe.
As a starting point, you should buy the excellent book from O'Reilly: Unix in a nutshell.
Hope this helps!
Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2000 03:07 AM
11-30-2000 03:07 AM
Re: Shell script problem
# remove empty files first
find /users/admin/output -type f -size 0 -exec rm {} \;
# move the remaining files but not the keep directory
cd /users/admin/output
mv !(keep) keep
Best regards,
Dan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2000 03:10 AM
11-30-2000 03:10 AM
Re: Shell script problem
I forgot the book....
Unix Power Tools
Jerry Peek, Tim O'Reilly and Mike Loukides
O'Reilly and Associates
ISBN 0-679-79073-x
Dan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2000 03:15 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2000 05:25 AM
11-30-2000 05:25 AM
Re: Shell script problem
Thank you all for your postings.
Cheers,
Barry.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2000 09:40 AM
11-30-2000 09:40 AM
Re: Shell script problem
The problem with your script is that you are trying to test $i from your current directory. You must put in the full path name in the if statement for it to work.
Using Frederic's example (use single brackets), the if statement should read
if [ -s "/users/admin/output/$i" ]
You can also cd to /users/admin/output before doing the for loop. This would allow you to remove the full path from the if statement. Hope this helps.
Josef