- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- AWK 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
06-16-2003 03:05 AM
06-16-2003 03:05 AM
I would like to insert a line:
"auth.warn @mickey.msc.com" into the file /etc/syslog.conf. This line is to be inserted after the first opening comment blocks:
#ident "@(#)syslog.conf 1.393/12/09 SMI" /* HP11.0 */
#
#
# syslog configuration file.
#
# This file is processed by m4 so be careful to quote (`') names
# that match m4 reserved words. Also, within ifdef's, arguments
# containing commas must be quoted.
#
# Note: Have to exclude user from most lines
# so that user.alert and user.emerg are not
# included, because old sendmails
#will generate them for debugging #information. If you
#have no 4.2BSD based systems doing network
#logging, you
#can remove all the special cases for "user"
#logging.
Below is my script which is intended to insert the line "auth.warn @mickey.msc.com" into the /etc/syslog.conf file.
#!/bin/sh
gawk '/#/{
if(startHash==0){
startHas=1;
};
};
$0 !~/#/{
if(startHash==1){
startHash=2;
print"auth.warn @mickey.msc.com"
}
else{
print $0
}
}' syslog.conf
Unfortunately, the "auth.warn @mickey.msc.com" does not get printed into the file /etc/syslog.conf.
I could have done:
echo "auth.warn mickey.msc.com" >> /etc/syslog.conf
which would place this entry at the bottom most of the file.
However, I would like to have this entry at the very beginning of the /etc/syslog.conf i.e after the 1st comment blocks of /etc/syslog.conf.
Could someone show me how it's to be done?
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2003 03:09 AM
06-16-2003 03:09 AM
Re: AWK Shell script problem
startHas=1;
};
You are missing the 'h' at the end of the variable name! Therefore the variable you test (startHash) never gets set!
Share and Enjoy! Ian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2003 03:19 AM
06-16-2003 03:19 AM
Re: AWK Shell script problem
first of all there is a typo in the script (startHas=1 instead of startHash=1) which will definitely prevent it from working.
Secondly, as written gawk will write its output to stdout.
You could redirect the output to something like /etc/syslog.conf-new, and then
mv /etc/syslog.conf /etc/syslog.conf-old
mv /etc/syslog.conf-new /etc/syslog.conf
HTH,
Michael.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2003 03:19 AM
06-16-2003 03:19 AM
Re: AWK Shell script problem
Unfortunately it still did not print the line "auth.warn @mickey.msc.com" into the /etc/syslog.conf file.
Any further ideas?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2003 03:30 AM
06-16-2003 03:30 AM
Re: AWK Shell script problem
I tried what you suggested, but it still did not produce the result:
gawk '/#/{
if(startHash==0){
startHash=1;
};
##CHANGED THIS LINE
print > syslog.conf.1
};
$0 !~/#/{
if(startHash==1){
startHash=2;
#print"auth.warn @pgldev01.png.intel.com"
echo "auth.warn @pgldev01.png.intel.com" >> syslog.conf.1
## ADDED THIS LINE
cp syslog.conf.1 syslog.conf
}
else{
print $0
}
}' syslog.conf
Instead it produced the error:
gawk: cmd. line:5: print > syslog.conf.1
gawk: cmd. line:5: ^ parse error
gawk: cmd. line:11: echo "auth.warn @pgldev01.png.intel.com" >> syslog.conf.1
gawk: cmd. line:11: ^ parse error
gawk: cmd. line:12: cp syslog.conf.1 syslog.conf
gawk: cmd. line:12: ^ parse error
gawk: cmd. line:12: cp syslog.conf.1 syslog.conf
gawk: cmd. line:12: ^ parse error
Could you show me how's to be done?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2003 03:48 AM
06-16-2003 03:48 AM
Solutioncat /tmp/testfile |awk 'BEGIN {found=0} found == 0 && $0 !~ /^#/ {print "auth.warn @mickey.msc.com";print $0 ;found=1}
found != 0 || $0 ~ /^#/ {print $0}' >/tmp/testfile2
cat /tmp/testfile2
This code works. I think the problem was your code is too complex for the job it needs to do. Share and Enjoy! Ian
Output from test code as follows,...
# comment block 1
# end comment block 1
auth.warn @mickey.msc.com
# comment block 2
# comment block 2a
# comment block 3
# comment block 3a
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2003 03:49 AM
06-16-2003 03:49 AM
Re: AWK Shell script problem
Michael.
#!/bin/sh
gawk '/#/{
if(startHash==0){
startHash=1;
};
};
$0 !~/#/{
if(startHash==1){
startHash=2;
print"auth.warn @mickey.msc.com"
# Now print the original line as well
print $0
}
else{
print $0
}
}' syslog.conf >syslog.conf-new
mv syslog.conf syslog.conf-old
mv syslog.conf-new syslog.conf
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2003 05:15 AM
06-16-2003 05:15 AM
Re: AWK Shell script problem
BEGIN {
p=0
}
/^#/ {p++ }
{if (p==0) {print "auth.warn@mickey.msc.com "; p=2
}}
{if (p==1) p=0}
{print $0
}
run:
awk -f awkfile /etc/syslog.conf
and redircet the output
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2003 01:45 AM
06-17-2003 01:45 AM
Re: AWK Shell script problem
I tried the solution from Michael and the changes are now reflected in the /etc/syslog.conf file.
However, the comment block beginning with "#" are not reflected in the new file or new output.
Could anyone of you show me how I could preserve all comment blocks in the /etc/syslog.conf file once the line auth.warn @mickey.msc.com
is included?
Thanks
PS: Attached is the /etc/syslog.conf file after the inclusion of the line:
auth.warn @mickey.msc.com
Note that the "#" are not present compared to the original.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2003 07:49 AM
06-17-2003 07:49 AM
Re: AWK Shell script problem
Share and Enjoy! Ian