Logging in unix account taking password from a parameter file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Logging in unix account taking password from a parameter file
# 1  
Old 04-17-2011
Logging in unix account taking password from a parameter file

Hi All,

I am writing a script where it updates a file in an unix account.
To update that file i need to be logged in as that account user.

say account name is ab01 and its password is passab01.

What i want to do is, my script should read login id and password from a parameter file and login to that environment.

Parameter file

ab01 passab01
ab02 passab02
ab03 passab03
.... and so on

before running script
server1:/home/oper/pkbond> id
uid=121(pkbond) gid=101(oper)

after running script
server1:/home/oper/ab01> id
uid=121(ab01) gid=101(oper)


Please help

Thanks in Advance Smilie

Regards,
pkbond
# 2  
Old 04-17-2011
This sounds a bit difficult using shell script. Try enabling ssh for the required users, that should be a cake walk. If you still want to do it with script, probably you should try expect

regards,
Ahamed
# 3  
Old 04-17-2011
I dont know exeactly what do you want but i try to make some simple script.

first of all you have to root permission.
if you change home directory other user then you need write permission in home directory else we get error like in below (permission error)
after you must run visudo and add pkbond to wheel group.
because of usermod is neccessary us and this is super command.

Code:
# usermod -G wheel pkbond

Code:
# cat /usr/etc/.paramlist
ab01 passab01 pkbond
ab02 passab02 ??????

Code:
[pkbond@rhnserver ~]$ ./justdoit
Before  running script
/home/oper/pkbond
uid=514(pkbond) gid=514(oper)
mkdir: cannot create directory `/home/oper/ab01': Permission denied
Only root can do that.
ab01 processes are OK!!
 
After running script
/home/oper/ab01
uid=514(ab01) gid=514(oper)
 
ab02 is not logged or is not parameter list!!

Code:
[pkbond@rhnserver ~]$ cat justdoit
#!/bin/bash
## justdoit
parameterfile=/usr/etc/.paramlist
#chown pkbond.pkbond $parameterfile
#chmod go-rwx $parameterfile
shopt -s expand_aliases
alias usermod='sudo '/usr/sbin/usermod' '
HOME=/home/oper
USER=$(id -un)
change_users () {
 while read -r newuser passwd loggeduser
  do
   if [[ $(who -u | grep $USER ) ]] && [[ $(echo $loggeduser | grep $USER) ]]  ; then
    echo -e "Before  running script \n$(finger $USER |awk '/Direct/ { print $2 }') \n$(id $USER |sed 's/\([^ ]* [^ ]*\).*/\1/')\n"
    mkdir -p $HOME/$newuser ; usermod -d $HOME/$newuser $USER
    usermod -l $newuser $USER ; echo "$passwd" | passwd --stdin $newuser ; echo "$newuser processes are OK!!" ; echo
    echo -e "After running script \n$(finger $newuser |awk '/Direct/ { print $2 }') \n$(id $newuser |sed 's/\([^ ]* [^ ]*\).*/\1/')"
   else
    echo -e "\n$newuser is not logged or is not parameter list!!"
   fi
  done < $parameterfile
}
change_users ""


regards
ygemici
# 4  
Old 04-17-2011
I really wish people would stop suggesting expect as the duct-tape universal solution to interactive login issues. They're often not doing you any favors and inviting the creation of moon-sized security holes. These utilities are designed to prevent you from using stored plaintext passwords for a reason -- it's a really bad idea.

Do what you need to do as root instead, or perhaps with sudo configured to let you and only you do this and only this one particular thing as root, in one particular way. Things shouldn't prompt you for user passwords when you're root, which prevents the need for an insecure file holding the passwords for every user on your system, in plaintext. Sheesh!
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 04-17-2011
Quote:
Originally Posted by Corona688
I really wish people would stop suggesting expect as the duct-tape universal solution to interactive login issues. They're often not doing you any favors and inviting the creation of moon-sized security holes. These utilities are designed to prevent you from using stored plaintext passwords for a reason -- it's a really bad idea.

Do what you need to do as root instead, or perhaps with sudo configured to let you and only you do this and only this one particular thing as root, in one particular way. Things shouldn't prompt you for user passwords when you're root, which prevents the need for an insecure file holding the passwords for every user on your system, in plaintext. Sheesh!
I agree completly you.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Logging in to 100 server to test my account

I have been logging to 100 server everyday to test if I can login to the server. I created a script to ssh-copy-id to every host so next time it will be password less. Now it keeps prompting me Are you sure you want to continue connecting (yes/no)? yes This is normal for first time login.... (2 Replies)
Discussion started by: invinzin21
2 Replies

2. Shell Programming and Scripting

Get the two parameter from text file in UNIX.

Hi there, In my attachment there is 'Category/Subcategory' & 'Setting'. var=$(awk '/^Logon\/Logoff/ {P=0} P {print $0} FNR==1{printf("From file %s:\n", FILENAME)} /^System/ {P=1}' $file |grep -ia "IPsec Driver" );echo $var As of now I am able to From File: Policies.txt IPsec... (2 Replies)
Discussion started by: alvinoo
2 Replies

3. Shell Programming and Scripting

Tar file with logging and directory via parameter

Hi all, I am fairly new to shell scripting and I am trying the following: My shell script creates a tar file with files with the ending ~. The directory - where the files and sub directories are located - comes as a parameter when I call the script. Files that are archived will be written in... (1 Reply)
Discussion started by: neg42
1 Replies

4. Shell Programming and Scripting

Taking mirror copy of the application id and password into the new UNIX machine

I am working in Datastage Migration project. The applications has to be moved from legacy machines to the new machines. all the applications will be having their own application id and password (non expiry) created in the unix (5.3). Now the scripts and the datastage applications has to be moved... (1 Reply)
Discussion started by: kmanivan82
1 Replies

5. UNIX for Dummies Questions & Answers

SQLPLUS Password Parameter file being used when logging in

Good day to everyone. This is my first time posting and just barely above basic Unix training. I think i have search thoroughly to ensure my question hasn't already been posted. But on the off chance the answer has been posted, please be nice as I am not 100% sure I know what I am looking for. I... (1 Reply)
Discussion started by: Mrjester
1 Replies

6. UNIX for Dummies Questions & Answers

User account logging

Hi - I want to log commands typed by oraapps user with time into some log file on runtime. HISTTIMEFORMAT="%d/%m/%y %T " works but any one with oraapps user can delete the history. OS : RHEl 5.6 Any help is appreciated. (5 Replies)
Discussion started by: oraclermanpt
5 Replies

7. Shell Programming and Scripting

Execute via crontab taking username/password from file

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)
Discussion started by: jhon
2 Replies

8. UNIX for Advanced & Expert Users

How to update my account password on 100 unix server ?

Hi We have over 100 unix servers. They include linux,solaris,aix,hp and sgi. I use telnet for some and ssh for rest. Note: none of this server has expect which i can use to update.So i am looking for expert who can help me with their script or guide me write KSH script to automate this. Thank... (6 Replies)
Discussion started by: humaurtum
6 Replies

9. UNIX for Dummies Questions & Answers

Change Account to not lock account if password expires

I have access to 15+ UNIX boxes at work, and I do not consistently log onto all of them over time. When I do try to access one I havent been on in awhile, my account is locked as the password has expired. I need to request to the UNIX SA's that the password expiration is 90 days and that if it... (1 Reply)
Discussion started by: stringzz
1 Replies

10. UNIX for Dummies Questions & Answers

not taking password for su on mac os x

Hello, I can't install matlab on my new mac os X because I am not logged in as a superuser. I type su root and it doesn't take my password. It just says sorry. Is there a way to just reset it? Thanks, Z (3 Replies)
Discussion started by: zitz
3 Replies
Login or Register to Ask a Question