- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: AWK assistance! Please
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
Discussions
Discussions
Forums
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
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
тАО10-23-2001 04:23 PM
тАО10-23-2001 04:23 PM
AWK assistance! Please
second part of the script) that I am stuck on, I have read manuals and I guess they are just to vague for me. PROBLEM: I am trying to untar a ton of baby tar balls that are identified (named) by their node name (we have over 500 nodes). I figured awk was the best way to do this, I did a 'ls -l' on the dir that the mother tar ball unloaded the baby tar balls into. The mother tar ball (1st part of script) created baby tar balls into another dir. I output the 'ls -l' to a file called 'babytar' and I awk the 'babytar' file and print on the 9th column which gives me the node name that I need to identify the baby tar balls by. I am getting an error on 'while' statement and the 'do' statement, if there is anybody that can spot what I am missing, again, I will CROWN THEE!
--------------Cut and Paste of Script----------
#!/bin/ksh
cd /home/s1perf/test_dir/test_dump
ls -l > /home/s1perf/test_dir/babytar
awk '{print $9}' /home/s1perf/test_dir/babytar | sort | while read server ; do
if [[ -f $DATA/$Server.tar ]] ; then
yes| tar xvf $Server.tar
fi
done
chmod 777 *
exit 0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-23-2001 04:51 PM
тАО10-23-2001 04:51 PM
Re: AWK assistance! Please
while read Server ; do
or change your other references of $Server with $server
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-23-2001 05:25 PM
тАО10-23-2001 05:25 PM
Re: AWK assistance! Please
Now coming to your while statement, you are declaring the $ variable as "server" in the while loop but you are using "Server" in the subsequent lines. Case does matter in UNIX. So either replace "server" with Server or vice versa.
And it is a good practice to keep the $ variables in {}s if they are followed by extra characters. Like ${Server}.tar. It doesnt' matter much here but it does in some places.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-23-2001 05:28 PM
тАО10-23-2001 05:28 PM
Re: AWK assistance! Please
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-23-2001 05:29 PM
тАО10-23-2001 05:29 PM
Re: AWK assistance! Please
There seems to be a mismatch in the ""Server.tar""
and "'server"' in your script. Also, make sure
the DATA variable is defined.
-raj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-23-2001 05:48 PM
тАО10-23-2001 05:48 PM
Re: AWK assistance! Please
cd /home/s1perf/test_dir/test_dump
ls -l > /home/s1perf/test_dir/babytar
awk '{print $9}' /home/s1perf/test_dir/babytar
change to the above two lines to just:
ls -d | sort ...
if you really want the results of the "ls" in a file, do: ls -d | tee yourfilename | sort ...
| sort | while read server ; do
if [[ -f $DATA/$Server.tar ]] ; then
change $Server.tar to ${server}.tar
the {} isn't really necessary, but the S->s is
$DATA??? where is that defined?
yes| tar xvf $Server.tar
change $Server.tar to ${server}.tar
the {} isn't really necessary, but the S->s is
fi
done
chmod 777 *
if you want to change permissions on all the files you just untared, you'll need to add the -R option to the chmod if there are subdirectories
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-23-2001 11:27 PM
тАО10-23-2001 11:27 PM
Re: AWK assistance! Please
I assume the variable DATA is defined elsewhere, in which case the following should work for you:
========================================
#!/bin/ksh
cd /home/s1perf/test_dir/test_dump
ls | while read server ; do
test -f $DATA/${server}.tar && yes | tar xvf $DATA/${server}.tar
done
chmod 777 *
exit 0
=========================================
Don't forget that 'ls' sorts by default, and even though it outputs to the screen in multi-column format, internally it is one-per-line, so 'ls' on its own is OK.
I've added $DATA in the tar command too, don't know if that's what you want.
Rgds, Robin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-23-2001 11:43 PM
тАО10-23-2001 11:43 PM
Re: AWK assistance! Please
"ls -l | awk ..." vs. "ls -1" (one)
"while read" vs. "for name in"
This could be a streamlined version
#!/bin/ksh
cd /home/s1perf/test_dir/test_dump
for name in `ls -1` # add required sortflag to ls
do
if [[ -f $DATA/$name.tar ]] ; then
yes| tar xvf $name.tar
fi
done
The syntax error as already mentioned seems to me the uppercase "S" mismatch in your script.
Hope this helps
Volker
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-24-2001 12:42 AM
тАО10-24-2001 12:42 AM
Re: AWK assistance! Please
Volker ( and all):
`ls -1` create a new process, and can be changed by * that will be treated on the current shell.
Sort is not needed because you will treat whole directory, and * will show alfa. sorted.
I dont know why that yes.
So my command will be
for file in */*.tar
do
tar xvf $file
done
or
echo */*.tar | xargs -n 1 tar xvf
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-24-2001 01:19 AM
тАО10-24-2001 01:19 AM
Re: AWK assistance! Please
cd /home/s1perf/test_dir/test_dump
for server in *
do
test -f $DATA/${server}.tar && yes | tar xvf $DATA/${server}.tar
done
chmod 777 *
exit 0
-Santosh