?
Solved

Sudo using a script

Posted on 2012-09-18
10
Medium Priority
?
1,974 Views
Last Modified: 2012-09-27
I am trying to SCP a folder from windows to AIX. The folder on aix to which all the files are ftped is under user "newuser". From this folder, I need all these files to be copied out to a folder on the same box (owned by super user "dev22") with right permissions on all the files in sub-directories. I have set up the newuser"" on aix to login without entering a password while entering the sudo command.

How do i say in a shell script to
 login as sudo and copy the files from the initall folder to the folder owned by the super user.?

I ran the following comand and it error-ed out

ssh newuser@aix sudo su - dev22

who: 0551-012 The process is not attached to a terminal.
      Do not run who am i as a background process.
0
Comment
Question by:raaj4354
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 26

Expert Comment

by:pony10us
ID: 38411293
Use the -t flag to force a tty to be allocated:

ssh -t -l <username> <compname> 'sudo yum -y install expect'
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 38411311
... or better "-tt" ...
0
 

Author Comment

by:raaj4354
ID: 38411452
Sorry I did not quite get that ..so u want me to run ssh -t -l newuser@aix  'sudo yum -y install expect' ..?? Can you explain please ..!
0
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 

Author Comment

by:raaj4354
ID: 38411480
i am trying to execute these commands after i SSH into AIX .. (put these commands in a shell script permissions.sh)

sudo su -dev22
cd ../..folder/newfolder
cp -r code /to/some/folder

ran script  like

ssh user@aixdev1 sudo su - dev22 permissions.sh

The output :
+ ssh user@aixdev1 sudo su - dev22 permissions.sh
Password:
Sorry, try again.
Password:
Sorry, try again.
Password:
Sorry, try again.
sudo: 3 incorrect password attempts
0
 
LVL 26

Expert Comment

by:pony10us
ID: 38411538
What I gave was an example.  

ssh -t newuser@aix sudo su - dev22

Correct woolmilkporc?
0
 

Author Comment

by:raaj4354
ID: 38411587
Ran the above command the output :

Pseudo-terminal will not be allocated because stdin is not a terminal.
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,password,keyboard-interactive).
SSH: EXEC: completed after 609 ms
0
 
LVL 26

Expert Comment

by:pony10us
ID: 38411664
Try it this way:

ssh -t newuser@aix 'sudo su - dev22'
0
 
LVL 81

Assisted Solution

by:arnold
arnold earned 400 total points
ID: 38411764
sudo su is reduntant.

Create a script
#!/bin/bash
/bin/cp /home/newuser/filesofinterest /new/location
chmod -Rh 644 /new/location/file*
chown -RH dev22 /new/location


scp file newuser@aixbox:/home/users/
ssh newuser@aixbox 'sudo /home/newuser/runscrip.sh'

I'm not sufficiently familiar with AIX.

You might be able to setup a root based script to monitor the /home/newuser for new fils and validate that the files are valid using cksum, md5sum to avoid corruption during transfer I.e. incomplete transfer. Once validated the auto scheduled job does what you need.
0
 

Expert Comment

by:mrtexmex
ID: 38412363
Do you have root access to the AIX server?  you could set up rsync to keep the 2 folders synced up.
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 1600 total points
ID: 38412660
It looks as if you're not authorized to run "sudo su" without having to enter your own (= newuser's) password first - not the password of "dev22" or "root"!

Adding "NOPASSWD" to the respective "sudoers" entry will change this behavior.

Check what you're allowed to do with sudo on aixdev1 with:

ssh -tt newuser@aixdev1 sudo -l

But arnold is right, of course, "sudo su" is somewhat redundant.

Adding an entry to sudoers (using visudo) on aixdev1  like the following should be appropriate:

newuser ALL=(dev22) NOPASSWD: /path/to/permissions.sh

Now you can do:

ssh -tt newuser@aixdev1 sudo -u dev22 /path/to/permissions.sh

If you don't have permission to run "visudo" on aixdev1 you will either have to ask an admin of that box to do it for you or you must live with having to enter your own password each time you call "sudo".

wmp
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Fine Tune your automatic Updates for Ubuntu / Debian
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses
Course of the Month13 days, 16 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question