Need help make pkgadd command Non-Interactive

i use this command to make pkgadd non-interactive.
Command1:

echo | sudo /usr/sbin/pkgadd -n -a /u/base/admin -r silent.txt -d /tmp/dbs.pkg

This works fine if i run it as root user but when i run it with non-root user it prompts me for the password and then executes successfully thus making it "INTERACTIVE".

I know how to provide the password on the fly like below.
Command2:

echo 'mypasswordxxx' | sudo -S /usr/sbin/pkgadd -n -a /u/base/admin -r silent.txt -d /tmp/dbs.pkg

How can i combine Command1 and Command2 to make it run as non-root and install successfully without any prompt i.e no prompt for password for sudo and no prompt for pkgadd .

Note: I would prefer not to change the profile settings.

Kindly suggest.

---------- Post updated at 07:34 PM ---------- Previous update was at 05:21 PM ----------

Why not allow your user to run pkgadd without a password:

add the following to the bottom of sudoers:

mohtashims  ALL=(root)  NOPASSWD: /usr/sbin/pkgadd

The simply do:

echo | sudo /usr/sbin/pkgadd -n -a /u/base/admin -r silent.txt -d /tmp/dbs.pkg

Or setup a /usr/bin/mypkgadd script and only allow this to be run as root without password.

%pkgaddgroup  ALL=(root)  NOPASSWD: /usr/local/bin/mypkgadd

The /usr/local/bin/mypkgadd script could be something like this:

#!/bin/bash
[ $(/usr/bin/whoami) != "root" ] && exec sudo "$0" "$@"

echo | /usr/sbin/pkgadd -n -a /u/base/admin -r silent.txt -d /tmp/dbs.pkg
1 Like

Thank you .. it worked for pkgadd but i do not know the syntax for chown which i use in my scripts.

I added this mohtashims ALL=(root) NOPASSWD: chown to the sudoer but it throws syntax error.

Can you help me with the syntax.

/absolute/path/to/chown

1 Like

Unfortunately, i made the changes without the absolute path and now my sudoers file is corrupt.

sudo vi /etc/sudoers
>>> /etc/sudoers: syntax error near line 117 <<<
sudo: parse error in /etc/sudoers near line 117
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin

I am still logged on to the box but the sudo commands fail with the error msg above.

This is why you use visudo, not sudo vi to edit /etc/sudoers.

There was probably a warning in the file telling you such, like there is in mine:

## sudoers file.
##
## This file MUST be edited with the 'visudo' command as root.
## Failure to use 'visudo' may result in syntax or file permission errors
## that prevent sudo from running.
##
## See the sudoers man page for the details on how to write a sudoers file.
##

Now you will need real root access to fix it.

sudo may have had security features preventing you from raw editing it anyway - it might not work again, even fixed, until you run visudo and re-save from root.

i have root access like i login with user1 and then sudo to root.

How do you login as real-root access user? Can you please elaborate ?

Log in with the username 'root' and root's password. This usually can't be done over ssh, only over a local terminal.

If you have a user with administrative privileges (meaning can change from system to system, membership in the 'wheel' group is sometimes sufficient) you can 'su - root', type in root's password, and login as root. This is an actual login, and does not involve sudo, or require a local terminal.

1 Like

As an outcome of this thread all suggestions point to making some or other change to the sudoers file.

So, can we conclude that the query in the OP cannot be resolved without modifying the sudoer file ?

Please confirm.

I am sorry to say it but it seems that you lack so many basic fundamental things working with Unix/Linux and it also seems that all those really many threads of yours in the forum and all the answers you got, do not change a bit to that fact.
You might want to take a basic lesson in administering a system.
Because of this, I will set your account to read-only for 3 months so you have time to catch up a bit.

Cheers
zaxxon

1 Like