- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Run awk script from within KSH script
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
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
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
12-19-2011 09:51 AM
12-19-2011 09:51 AM
Run awk script from within KSH script
Hello all,
Could someone please assist? I have an AWK routine the successfully prints a warning message for filesystem usage equal/greater than 90% when called as: df -k | awk -f script.awk
I would like to call the entire routine from within a KORN shell script. I can't seen to get it to work, please see below:
df -k | awk '{
{
if($1=="Filesystem")
next
}
{
for(i=1;i<=NF;i++)
if($i ~/%/)
FLD=i
if($FLD !~/-/)
usage=sprintf("%d\n", substr($FLD,1,index($FLD,"%")-1)+0)
if(usage>=90)
printf("%s;%s%s%d%s\n", "Filesystem warning",$NF," usage at ",usage,"%")
}
}'
Any help would be appreciated, Thanks
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2011 09:59 AM - edited 12-19-2011 10:03 AM
12-19-2011 09:59 AM - edited 12-19-2011 10:03 AM
Re: Run awk script from within KSH script
>I would like to call the entire routine from within a KSH script. I can't seen to get it to work
What's failing, what errors do you get?
You also seem to have an extra level of {} that you can remove:
df -k | awk '
...
printf("%s;%s%s%d%s\n", "Filesystem warning", $NF, " usage at ", usage, "%")
}'
And it would help if you had more indentation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2011 10:02 PM
12-19-2011 10:02 PM
Re: Run awk script from within KSH script
>I have an AWK routine the successfully prints a warning message
I'm not sure how? I had to change your script to:
df -k | awk '
{
if ($1 == "Filesystem")
next
if (substr($0, 1, 1) == "/")
filesys=$1 # save filesystem name
FLD = -1
for (i=1; i<=NF; i++)
if ($i ~ /%/) FLD=i
if (FLD == -1 || $FLD ~ /-/) next # skip all but lines with "%"
usage = $(FLD - 1) + 0 # get previous field
if (usage >= 90)
print "Filesystem warning;" filesys, "usage at", usage "%"
}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2011 09:38 AM
12-20-2011 09:38 AM
Re: Run awk script from within KSH script
Many thanks for the post.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2011 11:29 AM
12-20-2011 11:29 AM
Re: Run awk script from within KSH script
Or you could use bdfmegs -qP 90
That will report nothing if no filesystems are 90% or larger, otherwise, one filesystem per line.
bdfmegs never splits long lines which makes it ideal for scripting.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2011 03:24 PM
12-20-2011 03:24 PM
Re: Run awk script from within KSH script
>Many thanks for the post.
If you are happy, please click on the Kudos star.
And if it is a solution, you can use the post Options mention to mark it as a solution.