Need help make pkgadd command Non-Interactive


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help make pkgadd command Non-Interactive
# 1  
Need help make pkgadd command Non-Interactive

i use this command to make pkgadd non-interactive.
Command1:
Code:
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:
Code:
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 ----------
# 2  
Why not allow your user to run pkgadd without a password:

add the following to the bottom of sudoers:
Code:
mohtashims  ALL=(root)  NOPASSWD: /usr/sbin/pkgadd

The simply do:
Code:
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.
Code:
%pkgaddgroup  ALL=(root)  NOPASSWD: /usr/local/bin/mypkgadd

The /usr/local/bin/mypkgadd script could be something like this:
Code:
#!/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

This User Gave Thanks to Chubler_XL For This Post:
# 3  
Tools

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.
# 4  
/absolute/path/to/chown
This User Gave Thanks to Corona688 For This Post:
# 5  
Error

Quote:
Originally Posted by Corona688
/absolute/path/to/chown
Unfortunately, i made the changes without the absolute path and now my sudoers file is corrupt.

Code:
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.
# 6  
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:

Code:
## 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.

Last edited by Corona688; 02-06-2017 at 01:41 PM..
# 7  
Quote:
Originally Posted by Corona688
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:

Code:
## 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 ?
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #708
Difficulty: Medium
The MySQL SELECT statement allows you to read data from only a single table.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Non-interactive pkgadd not working.

Inorder to make the pkgadd non-interactive i tried couple of things but both failed. 1. sudo pkgadd -n /u/mont/admin -d /u/mont/dbprd.pkg pkgadd: ERROR: no packages were found in </var/spool/pkg> 2. yes all | sudo pkgadd -a /u/mont/admin -d /u/mont/dbprd.pkg ... (0 Replies)
Discussion started by: mohtashims
0 Replies

2. Shell Programming and Scripting

Shell script using an interactive command

Hello experts, I have a to write script for monitoring, the script would use a command and I plan to write the script as follows while true do command -arg sleep 2 clear done The output would be set up on a screen for monitoring. However the issue is that the command used in... (2 Replies)
Discussion started by: maverick_here
2 Replies

3. Shell Programming and Scripting

Expect command use for interactive mode of scripting

Hi All, I am writing a script(Auto_Installation.sh) which is calling one another script (./update_manager /spare/install/HO7/PME_Response_file.txt) Now the issue is result of (./update_manager /spare/install/HO7/PME_Response_file.txt) script is ##########################################... (6 Replies)
Discussion started by: Dhruvak
6 Replies

4. Shell Programming and Scripting

How to make command line interactive?

I have a file with stats for different month, I use the cat and grep combination to search for different month. cat <file> | grep "April" cat <file> | grep "May" cat <file> | grep "June" etc. How do you make this command interactive. So that I can give the values for the search. Thanks... (7 Replies)
Discussion started by: purelltab
7 Replies

5. AIX

Non interactive command output using script command ?

Hello, Script command helps to save command output to file. (Redicection doesn't work in this case). Besides interactive shell 'recording', Linux script command has "-c" option which allows to record output of some non-interactive command. The problem is that AIX script command variant... (6 Replies)
Discussion started by: vilius
6 Replies

6. Homework & Coursework Questions

How to write script that behaves both in interactive and non interactive mode

Q. Write a script that behaves both in interactive and non interactive mode. When no arguments are supplied it picks up each C program from the directory and prints first 10 lines. It then prompts for deletion of the file. If user supplies arguments with the script , then it works on those files... (8 Replies)
Discussion started by: rits
8 Replies

7. UNIX for Dummies Questions & Answers

nohup has a terrible bad performance compared with interactive command, why?

I have a strange situation. I'm running a shell script containing several data uploads (using Oracle sqlloader utility). This script is being run on a Red Hat server. I tried to run it in background: $ nohup upload.sh & This script uploads some thousands files. After several hours I... (0 Replies)
Discussion started by: viniciov
0 Replies

8. Shell Programming and Scripting

How to make interactive shell script a automated one?

Hi, I am new to shell scripting.I have written a very simple shell scipt that asks for the username and password on executing. i.e echo "Enter username :" read usrname; echol "Enter password :"; read passwd; echo usrname; echo passwd; but now I want to make it automatic , such... (2 Replies)
Discussion started by: bhaskar_m
2 Replies

9. UNIX for Advanced & Expert Users

SU command in non interactive mode

Can i run the SU command in a non interactive mode. What i want to do is to pass the username and the password as commandline or batch parameters. Please let me if its possible and how to pass them. A sample file will be appreciated. Thanks, (6 Replies)
Discussion started by: rohitag
6 Replies

10. Shell Programming and Scripting

How to make a cshell (csh) script interactive

Experts, I tried to make my cshell script interactive by asking the user for password and trying to read the input using the "read" command. I have been unsuccessful so far. Do you have any idea ? Thanks Jim (2 Replies)
Discussion started by: jimmynath
2 Replies

Featured Tech Videos