0

so I would like to know how to create a script the performs three basic commands.

sudo su - Admin
     cd ~/AMP
     ./ampinstmgr -a

This is what I got, I have also given it 777 perms.

#! /bin/sh
# /etc/init.d/run.sh
#

# Some things that run always
touch /var/lock/run

# Carry out specific functions when asked to by the system
case "$1" in
  start)
     sudo su - Admin
     cd ~/AMP
     ./ampinstmgr -a
    ;;
  stop)

    ;;
  *)
    exit 1
    ;;
esac

exit 0

1 Answers1

0

Rather than 3 commands

sudo su - Admin
 cd ~/AMP
 ./ampinstmgr -a

Simply use sudo to execute the command as user Admin directly (and don't rely on ~ expansion but use absolute paths in sudo commands):

sudo -u Admin /home/Admin/AMP/ampinstmgr -a
HBruijn
  • 72,524
  • 21
  • 127
  • 192
  • So is there anything that I have to do to make this script run in the init.d folder? I changed it to sudo -u Admin /home/Admin/AMP/ampinstmgr -a –  TheSourceCode Jun 22 '17 at 19:55