- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Shell Scripting
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
02-10-2003 09:34 AM
02-10-2003 09:34 AM
I'm writing a script to automate some tasks on the network. The problem that I came a cross is that I don't know how to open /etc/passwd file, edit the line, saved and exit.
What I would like to do is the next:
our PDC is on HP-UX 11.00.
In order for the workstation to join domain, it has to have $ in the end of the name e.g.
wsat1210$:*:125:102:MVRMachine:/dev/null:/bin/false
This is not a standard characters for the password file, so I can't do that via SAM.
I know that there is the command to open file for editing, but I didn't have too much luck doing it.
Thank you
Miro
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2003 09:45 AM
02-10-2003 09:45 AM
Solutionsed 's/wsat1210/wsat1210$/' /etc/passwd>/tmp/somefile
mv /tmp/somefile /etc/passwd
This uses the 'swap' command to exchange "wsat1210" with "wsat1210$", and copies the result into a temporary file. The second command copies the temporary file over the original. It would be an EXCELLENT idea to make a backup copy of your password file before attempting this.
Good Luck
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2003 09:46 AM
02-10-2003 09:46 AM
Re: Shell Scripting
But, to make a change to any file, many tools exist. Some of the more popular are "perl", "awk", and "sed".
Using "sed" you could do the following (again editting the /etc/passwd file could have unexpected results, especially on a "trusted" system) -
sed -e 's/^wsat1210:/wsat1210$:/' /etc/passwd2
mv /etc/passwd /etc/passwd.orig
mv /etc/passwd2 /etc/passwd
Good Luck (be sure you have good backups...)
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2003 10:04 AM
02-10-2003 10:04 AM
Re: Shell Scripting
Are you confusing workstation name with username ??? ==> "In order for the workstation to join domain"
What kind of "domain" requires a $ at the end of a users name?
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2003 10:26 PM
02-10-2003 10:26 PM
Re: Shell Scripting
As for you Miro i have nothing much to add over the info the others have posted.
regards,
Ramkumar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2003 11:36 PM
02-10-2003 11:36 PM
Re: Shell Scripting
I guess you do know $user ??
#!/bin/ksh
userline=`/usr/bin/cat /etc/passwd | grep "^${user}:"`
/usr/bin/cat | grep -v "^${user}:" >/etc/passwd.mv
user="${user}\$"
userline=`echo $userline | awk -F: '{print $2 ":" $3 ":" $4 ":" $5 ":" $6 ":" $7}'`
userline="${user}:${userline}"
echo "$userline">>/etc/passwd.mv
rt=`/usr/bin/diff /etc/passwd /etc/passwd.mv`
if [ "$rt" < "5" ]
then
mv /etc/passwd.mv /etc/passwd
else
/usr/bin/logger -p user.warning "$0: Error in addapting user !!"
fi
I prefer perl for doing things like this, but he. You have to be able to understand perl for that. And as you can see I'm not very good at writing shell-scripts.
Regs David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2003 02:26 AM
02-11-2003 02:26 AM
Re: Shell Scripting
Try the following lines:
awk 'BEGIN { FS = ":"; OFS = ":"} {$1=$1"$"; print $0}??? /../yourfile > file1
mv file1 /../yourfile
Hope this help you!!!
Regards,
Sylvia
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2003 04:57 AM
02-11-2003 04:57 AM
Re: Shell Scripting
Miro
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2003 06:34 AM
02-11-2003 06:34 AM
Re: Shell Scripting
Lots of neat solutions. Here is a real easy one. Use the 'useradd' command as root and you can specify a '$' in the user ID. Like this:
useradd -u 50001 -g users -d /home/users/testjp "testjp$"
This gives me this entry in /etc/passwd:
testjp$:*:50001:20::/home/users/testjp:/sbin/sh
Of course, you'll still have to set the password but you can use the 'passwd' command to set the password discipline, requiring a change at the first login.
Just one way to do it.
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2003 06:59 AM
02-11-2003 06:59 AM
Re: Shell Scripting
# tail -1 /etc/passwd
testjp:*:50001:20::/home/users/testjp:/sbin/sh
# usermod -l "testjp$" testjp
# tail -1 /etc/passwd
testjp$:*:50001:20::/home/users/testjp:/sbin/sh
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2003 11:42 AM
02-11-2003 11:42 AM
Re: Shell Scripting
Try this:
#!/bin/tcsh
# SCRIPT
set numPassLines = (`grep -c ":" passwd`)
@ i = 1
while ( $i <= $numPassLines )
echo $ >> passwd
echo -n "Gx" >> temp_vi_cmd
echo -n "$i" >> temp_vi_cmd
echo -n "G" >> temp_vi_cmd
echo "wP" >> temp_vi_cmd
echo "ZZ" >> temp_vi_cmd
(vi passwd < temp_vi_cmd) >> & temp
rm -f temp temp_vi_cmd
@ i ++
end
unset numPassLines