Help with calling to file for a username and password combo
Hokay...first post, and I have been doing Linux scripting for a total of 2 days now. I think I am doing pretty well, but awk and arrays(what I think I need here) is a bit above me so far.
I have written a script that will take and either create or modify 5 users, and passwords.
It checks the device to see if a user exists, if they don't, it adds the user, and gives them sudo access, and changes the password to the one specified. If they do exist, it changes the password to the specified password, and then checks for sudoers access, and gives the user access if they don't have it.
Currently this script isn't really scaleable. it us for 5 users. It can be tweaked to add more, but I know there is a better way to do it, I just don't know how at my level of knowledge.
What I want to have it do, is call to a text file that has something like
username password
username password
username password
And have set the username and password on each line, on loop, till EOF. I don't know how to do that, and have it keep username on line1 with username on line1, and username on line2 with username on line2 successfully.
I have already seen a few ways I can clean up the existing code and make it cleaner, but I am trying to get this part figured out before tomorrow night first.
If you have any help, please let me know.
Here is my current script: (it is much cleaner than how it pasted in here)
You can use logic similar to the following. This assumes each line contains a space separated username/password combo. You can then just act upon $username and $password on each loop cycle:
EDIT: I think I am starting to get a better grasp of it.. Still not entirely sure where $username and $password are coming from though.
Any chance of some comments of what is going on where? A lot of this is over my head. I have no clue now how the if statement is determining whether to do "then" or "else". Don't see where $username and $password are being set either, lol.
And I'm getting "line 34: [: too many arguments" on the below line:
if [ grep -q "^$username:" /etc/passwd ]
I'm gonna tear it apart for a while and see if I can figure out what is going on...
But thanks so much, I get a little of it, which is helping out immensely.
Quote:
Originally Posted by Chubler_XL
When writing functions use positional parameters instead of hard-coded vars, reads user and password from file:
Not sure why your were using sh -c for the append to /etc/sudoers - changed to standard echo
Last edited by cashman04; 01-29-2013 at 10:21 PM..
EDIT: username and password come from the while read username password ; do ...... done < input_file statement. In shell if statements run a command and examine it's return code when zero the then part is executed otherwise the else part . ( [ is a shell builtin command used to do standard tests)
Last edited by Chubler_XL; 01-29-2013 at 10:38 PM..
Ok, I am taking this apart bit by bit to understand it. I pretty much get the $username and $password, and how you can use "while read" to get that info, and assign it..
Now though, how are you passing this to $1 and $2? and how does it know to run the command with say user1 and password1, and then user2 and password2 a different time? and over, until end of file?
the shell builtin while continues to run the code between do and done until the read statement returns non-zero (ie end of input file).
When you call a function (like changepass $username $password) $1 $2 $3... $n are populated from the arguments passwd on the function call (in this instance $1 = $username and $2 = $password, and $# is set to 2, indicating 2 arguments were passed).
This makes the changepass function quite useful as you can call it just like other unix commands and pass values directly in like:
Hi,
I know this sounds crazy question.. but I am just curious to know what happens next when I enter username and password and hit enter on a new Unix session (using Putty)? I mean which file gets executed, how the default login shell is determined etc...
regards
juzz4fun (5 Replies)
Picked up a 3b2 running System V. Works fine, but it requires a username and password. Is the username "root" or "sysadm"? How do I find out and how to I reset it or bypass it?
Thanks. (2 Replies)
Hi
I am new to using unix and am struggling with a script i am writing. What i am trying to do is get a user to enter a username, check the original file i created with username and pin to see if their is a corresponding entry. Next ask the user to enter the pin and see if this matches... (5 Replies)
hi all,
i run sqlplus command on unix(HP-UX)
like "sqlplus username/password@serverA @deneme.sql"
but when someone run "ps -ef | grep sqlplus", it can see my username and password :(
How can i hide username and password.
thanx. (1 Reply)
I have a RHEL 5 server that I can log into with an LDAP account hosted on a server running Sun DSEE 6.3 with an ssh key pair but not with my username and password. When I try to login to the console I am given the "login incorrect" message as if I fat fingered my password. Other users with... (5 Replies)
Hi,
I am encoding the username and password to the url and use it with wget.
I.e wget ftp://username:password@myserver.com/test.mp3
However this does not work if the password contains @ character. if the password contains @, then the encoded url becomes
wget... (1 Reply)
Dear All
Here is the details what i want to achieve from shell scripts
I have a sever where 5 databases are created. which i having diffrent SID's.
Now i want to execute some SQL queries on each one of the databases. (SQL Query is same).That i want to acheive via crontab
Now each one of the... (2 Replies)
Dear All
I am trying to write one shell which will be running through Cron which contain one SQL query. But I want to draw/fetch the Username password and Instance name (required to loging to the database) from one single file to run that SQL query . Also this file contain details of multiple... (2 Replies)
hi there,
Please help me
How transfer sql file from one server to another without username and password .i know just IP address.
Thanks
Arpit (1 Reply)
Can we write a script to telnet to a unix server from unix with the username and password hardcoded in the script??
something like ssh a@b -p password ??? (5 Replies)