Shellscript to Sudo other account


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shellscript to Sudo other account
# 8  
Old 11-26-2007
Here is my requirement to be more elaborate:-

I have a ram.inc file in account ramdev2:-

<username> ram </username>
<password> tttt </password>
<port-no> 1000 </port-no>
<data1> hhh </data1>
<data2> ttt </data2>

By using sudo -u ramdev2 i need to connect to the ramdev2 account and find the file "ram.inc" parse it and get only the port-no (which is 1000) and save this value in a .txt file and return it. All these needs to be done through a shell script. Please do provide a solution for this. I will be really thankful to u guys. It is really urgent.


Thanks,
Sachin
# 9  
Old 11-27-2007
Please do provide an answer...Since it is really urgent.
# 10  
Old 11-27-2007
Quote:
Originally Posted by sachin.tendulka
Please do provide an answer...Since it is really urgent.
This is not encouraged in the forum.

Please read the rules of the forum
# 11  
Old 11-27-2007
Sorry Madhan, I dont have any other choice where i need
to deliver this today. Since i am pretty new to shell scripts i am finding it difficult. Sorry if i have written anything wrong.
I read some of the suggestions given by you, pls. do provide a solution for this with an example. It will be really helpful.
# 12  
Old 11-27-2007
try this,

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


Last edited by matrixmadhan; 11-27-2007 at 02:23 AM.. Reason: quotes
# 13  
Old 11-27-2007
Madhan,

Using the command i am not able to get the port no. value in output file. I tried with few other options where nothing worked. Pls. do provide a solution.
# 14  
Old 11-27-2007
Quote:
Pls. do provide a solution.
I thought I gave that ! Smilie

just try this,

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

and post the output that you get !

The above one-liner is based on the sample file that is provided
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