- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Script help......
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
08-07-2001 09:02 AM
08-07-2001 09:02 AM
Sorry to appear lazy but I'd like to write a small script & would appreciate some quick tips as to how I should go about it.
I need a script that can be run on the command line with one text argument. The script will then need to append that argument onto the end of a specific line within a text file.
My problem is that I want admin users to be able to add users onto a group definition statement within the sudo config file /etc/sudoers. I'll have to make a copy firts & perform the append before copying it back over the actual file, this bit I think I can manage.
Any ideas as to the simplest way of doing this would be great.
Thanks
Phil C
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2001 09:15 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2001 09:19 AM
08-07-2001 09:19 AM
Re: Script help......
Not necessarily the "quick and dirty" method, but sed is quite useful. It allows you to do "vi" functions to a file in a single pass. You can redirect stdout to experiment and play it safe.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2001 09:26 AM
08-07-2001 09:26 AM
Re: Script help......
Consider this:
An input file called "myfile" like:
this is line1
this is line2
this is line3
...where you want to append your token to the end of "line2":
Then your script called "my.sh":
#!/usr/bin/sh
sed "s/line2/line2$1/" $2 > ${2).new
mv ${2}.new ${2}
To add the text string "added" to the "line2" token:
./my.sh added myfile
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2001 09:33 AM
08-07-2001 09:33 AM
Re: Script help......
Phil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2001 09:34 AM
08-07-2001 09:34 AM
Re: Script help......
There must be easy way but I know long way to do it in perl
#add_user username (this is how you run)
#/usr/contrib/bin/perl
open (FILE "/etc/sudoers") || die "can't open sudo file";
open (NEWFILE "/etc/newsudoers");
$uername=shift;
while
{
if (/User_Alias OPERATOR/) #if you want to add user_alias
{
$newline=$_.","$username
print NEWFILE $newline;
}
print NEWFILE $_;
}
mv /etc/newsudoers /etc/sudoers;
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2001 09:46 AM
08-07-2001 09:46 AM
Re: Script help......
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2001 09:47 AM
08-07-2001 09:47 AM
Re: Script help......
#test.dat file
line 1
line 2
line 3
.
.
adduser tester1
..
.
.
#end
No lets say you wanted to modify the adduser line. You could easily do this:
var1=`cat test.dat | grep adduser | cut -f1 -d" "`
sed 's/'${var1}'/'${1}'/ test.dat > test.out;mv test.out test.dat
Hope this helps.
...jcd...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2001 09:56 AM
08-07-2001 09:56 AM
Re: Script help......
Anyway, in my reponse, it is field 2 not field 1
var1=`cat test.dat | grep adduser | cut -f2 -d" "`
sed 's/'${var1}'/'${1}'/ test.dat > test.out;mv test.out test.dat
...jcd...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2001 10:04 AM
08-07-2001 10:04 AM
Re: Script help......
grep -n adduser test.dat | cut -f1 -d":"
Will give you the line number.
...jcd...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2001 10:38 AM
08-07-2001 10:38 AM
Re: Script help......
I've ended up using the following & it works just fine:
#!/usr/bin/sh
line=`grep 'User_Alias HELPDESK=' /etc/sudoers | cut -f1 -d":"`
sed "s/$line/$line,$1/" /etc/sudoers > /etc/tmpsudoers.new
mv /etc/tmpsudoers.new /etc/sudoers
Thanks again
Phil C