- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: useradd 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
05-27-2004 11:04 PM
05-27-2004 11:04 PM
I want to write one useradd shell script which will customised useradd command.
My script also ask for ftp user, cron user setup and according to it will
add ftpuser, cron user in respective files.
Also i want to write script in such a way that options will be in any order,
i mean, like below:
useradd.sh -g
Or
useradd.sh -s
or
useradd login
The missing options will be the default settings.
How can i write in my script that which argument for
for
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2004 11:19 PM
05-27-2004 11:19 PM
Re: useradd script help
Check the manpage of getopts.
It contains an interesting example too.
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2004 11:23 PM
05-27-2004 11:23 PM
Re: useradd script help
you will have to test your input parameters.
eg. if %1 is -s then %2 is shell. You hae to do this for all your input parameters.
There are a lot of different ways in which you can do this.
The if methed may be easiest to understand but it will require a lot of if statements.
Using another method like "case" would be better but everyone's got different preferences when scripting.
regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2004 11:57 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2004 01:55 AM
05-28-2004 01:55 AM
Re: useradd script help
Need more information. Are you wanting this script to be interactive or did you want the user to just type all of the info on a command line?
If you are looking for an interactive script, you could use something like this, but you would have to provide some error checking to ensure a valid shell is entered, a uid or gid is not being duplicated, etc.
echo "\nPlease enter username:"
read username
echo "\nPlease enter user id: "
read userid
echo "\nPlease enter group: "
read group
echo "\nPlease enter shell: "
read shell
echo "\nPlease enter home directory: "
read homedirectory
echo "\nPlease enter comment: "
read comment
echo "\nPlease enter username:"
read username
echo "\nPlease enter user id: "
read userid
echo "\nPlease enter group: "
read group
echo "\nPlease enter shell: "
read shell
echo "\nPlease enter home directory: "
read homedirectory
echo "\nPlease enter comment: "
read comment
useradd $username -u $userid -g $group -s $shell -d $homedirectory -c $comment"
You could even dump the info to a file so you can see all of the information that the user supplies:
echo "useradd $username -u $userid -g $group -s $shell -d $homedirectory -c $comment" >/tmp/useradd.test
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2004 02:07 AM
05-28-2004 02:07 AM
Re: useradd script help
Don't forget about SAM. You can use an additional script which is called from SAM before and/or after user's creation. You can put into the script all additional features.
HTH