Shellscript to Sudo other account


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shellscript to Sudo other account
# 15  
Old 11-27-2007
First of all thanks Madhan, i am able to get the output for a single keyword search(listen-port) .If i want to get the data for multiple keyword search what to do?
For eg,

sed -n 's/port-no/&/p' db.xml > example.txt

this works.

But when i try to search for 2 keywords like:-

sed -n 's/port-no/&/dbname/p' db.xml > example.txt

iam getting an error saying :-

"command garbled:"

How to find the data for 2 keywords(port-no and dbname) in the same db.xml?
# 16  
Old 11-27-2007
Madhan, your reply for this..
# 17  
Old 11-27-2007
Quote:
Originally Posted by sachin.tendulka
Madhan, your reply for this..
Quote:
(4) Do not 'bump up' questions if they are not answered promptly.
Here is my shot,

are you interested in all the data points along with the matching data header

something like,

Code:
sudo -u ramdev2 sh -c " sed -n 's/<\(.*\)>\(.*\)\(<\/.*$\)/\1-\2/p' inputfile "


this will give output something like,
Code:
username- ram
password- tttt
port-no- 1000
data1- hhh
data2- ttt

# 18  
Old 11-28-2007
Madhan, Once again thanks i have written a shellscript
which gets the data from various files for a respective
name and append those data's in a sample.txt file. Here it is:-

parseData(){
param="$@"
sudo -u $param ksh -c sed -n 's/data-1/&/p' /home/$param/example.dat >> sample.txt
sudo -u $param ksh -c sed -n 's/data-2/&/p' /home/$param/example1.dat >> sample.txt

}

FILE="names.txt"
if [ ! -f $FILE ]; then
echo "$FILE : does not exists" exit 1
elif [ ! -r $FILE ]; then
echo "$FILE: can not read"
exit 2
fi
exec 3<&0
exec 0< $FILE
while read line
do
parseData $param
done
exec 0<&3

exit 0

I will be passing names.txt as a command line arg.which contains 10 names . Where each of those names have different HOMEDIR from where we can search the file and get the data. My problem is that i know the HOMEDIR of my name jason( /home/jason/). But i dont know the HOMEDIR for other names. So how i can find the HOMEDIR for other names and for there how can search the example.dat and example1.dat(which is common for all names) and get the respective data?
I have used "~" like "~ /example.dat" but it is getting me the HOMEDIR of the current working directory.
How to solve this problem. One more problem is that when this script is invoked twice, the data's for the same name is appended twice because of ">>". I dont need that where i need to delete the file sample.txt (if it exists), each time when the script is invoked so that i will get only the data for partcular name once. Please do provide a solution for this..

Thanks
# 19  
Old 11-28-2007
Quote:
parseData $param
what is the value that is populated for $param ?

Quote:
So how i can find the HOMEDIR for other names
this should be possible from the file /etc/passwd

for each and every user from /etc/passwd file, home directory of the user can be obtained

Quote:
One more problem is that when this script is invoked twice, the data's for the same name is appended twice because of ">>".
If you are sure, that sample.txt file should be created afresh each time the script is run.

Add the following in the start of the script, to check if sample.txt exists and if it is
there delete the file, so that new copy of data would be directed to the file

Code:
if [ ! -f sample.txt ]
then
  /bin/rm sample.txt
fi

# 20  
Old 11-28-2007
BTW,

with this,

Code:
sed -n 's/data-1/&/p'

what is the intended effect that you wish to have with the above code ?
# 21  
Old 11-29-2007
Thanks Madhan, the sed line will get the data for the element data-1.
What is the command to get the HOMEDIR values from /etc/passwd. Where i need to set the HOMEDIR in a variable and then pass it to the "sed" command.
Some thing like :-

homedirvalue= "cat /etc/passwd/$HOMEDIR";

Please correct me in this.

Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

What happens to your skype account if you close outlook.com email account?

Hello, Does anyone know what happens to your skype account if you close the outlook.com email account which are linked together? As you know they are both owned by Microsoft. Thanks (0 Replies)
Discussion started by: milhan
0 Replies

2. How to Post in the The UNIX and Linux Forums

Simultaneously try to execute commands after connecting to remote account to one account

I have made password less connection to my remote account. and i tried to execute commands at a time. but i am unable to execute the commands. ssh $ACCOUNT_DETAILS@$HOST_DETAILS cd ~/JEE/*/logs/ (1 Reply)
Discussion started by: kishored005
1 Replies

3. Shell Programming and Scripting

Shellscript not executing further after sudo over a user

Hi, I am writing a switch case statement and one of the option contains sudo to a particular user and then perform some steps after that but my script is unable to proceed with further execution after doing sudo over the user. Could you please suggest an workaround for this. (1 Reply)
Discussion started by: adityam
1 Replies

4. Shell Programming and Scripting

ssh foo.com sudo command - Prompts for sudo password as visible text. Help?

I am writing a BASH script to update a webserver and then restart Apache. It looks basically like this: #!/bin/bash rsync /path/on/local/machine/ foo.com:path/on/remote/machine/ ssh foo.com sudo /etc/init.d/apache2 reloadrsync and ssh don't prompt for a password, because I have DSA encryption... (9 Replies)
Discussion started by: fluoborate
9 Replies

5. Shell Programming and Scripting

Issue in passing passwd to login into a sudo account

Hi Gurus, I have small issue... I used to pass the passwd for sudo commands like below, gzcat ~/passwd.gz | sudo su - <villin> >> eof ------ ----- ------ eof And it was able to login into "villin" sudo account successfully. But now, I'm using the same in another script for the... (2 Replies)
Discussion started by: raghu.iv85
2 Replies

6. Linux

Apply disk quota to account(dedicate 3 GB to account).

Hi , I am faceing lot of problem due to "disk space is not enough". senerio is like as, In system has 5 account. a,b,c,d,e say account c if very critical. Due to other user's data, user 'c' is faceing disk space issue. I want to dedicate 3 GB for user 'c'. No user... (1 Reply)
Discussion started by: ashokd009
1 Replies

7. 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

8. UNIX for Dummies Questions & Answers

Setting an account to be a non-login account automatically?

Is there a way to easily change an account to be a non login account (NP in the shadow) file? I know I can just edit the file but that is not what we want to do. We use access control software and want to provide a way to set an account to be non-login using simple commands that can be mapped... (0 Replies)
Discussion started by: LordJezo
0 Replies

9. UNIX for Dummies Questions & Answers

Account creation Sudo enabled

Hi, how to create account with the following be cron enabled only accessible via sudo (1 Reply)
Discussion started by: vilves
1 Replies
Login or Register to Ask a Question