-1

I logged in as a super user in Unix, I need to write a script to make a change in directory permission in the root user without logging out of the super user. When I execute this script the flow stops abruptly and it is not going forward. Below is the script that I am using.

sudo -u user1 chmod 777 /export/home/user1
cd /u01/app/informatica/infa_etl/Informatica/server/infa_shared/TgtFiles
sudo -u super cp *csv /export/home/user1/RPT_GEN
sudo -u user1 chmod 700 /export/home/user1

Thanks in advance

Gokul.M
  • 47
  • 1
  • 6

1 Answers1

2

A shell script is not a list of keystrokes to send to your shell. It's a program that is executed by the shell. So, since the first line of your script is exit, the first thing the shell will do is exit, and nothing else in the script can be executed because the shell is no longer running.

It's not clear to me what you want your script to do, but for it to have any chance of working, you'll definitely need to eliminate the exit statements. Your call to sudo will also not work as you probably expect. If you need to execute a command as another user, you should use the sudo command like this:

sudo -u other_username command_to_run

So if you want to copy some files as a user named super, the invocation would be:

sudo -u super cp *csv /export/home/user1/RPT_GEN

Hope this helps.

Charley
  • 578
  • 3
  • 13
  • I have modified the question a bit for your better understanding. I tried implementing your solution but it is asking some password for every line in the script. – Gokul.M Jan 19 '18 at 10:25
  • You've clarified your question a bit, but the script you show in the question hasn't changed, so I don't know what your script looks like now. – Charley Jan 19 '18 at 10:30
  • Please check the modified script. – Gokul.M Jan 19 '18 at 10:43
  • Please remember to check the preview before saving your edits. Your script is now very hard to read. Four spaces at the beginning of each line will render your code with a more readable style. – Charley Jan 19 '18 at 11:07
  • If the problem is now that it asks for a password, then you may need to review your `sudoers` configuration. If you need this script to work non-interactively then you will need a password-less sudo configuration. – Charley Jan 19 '18 at 11:08