Rpm sign command uses getpass() method to read passphrase and hence there is no direct way to send passphrase by redirection in a shell script.
One alternative to that is to use Expect script (You need to have expect installed. RPMs are available in standard linux distros). Here is a snippet of code that explains how it works:
########BEGIN#############################
function expect_script
{
cat << End-of-text #No white space between << and End-of-text
spawn rpm --resign $RPMFILE
expect -exact "Enter pass phrase: "
send -- "${RPMPWD}\r"
expect eof
exit
End-of-text
}
function sign_rpm
{
echo "Signing RPM..."
expect_script | /usr/bin/expect -f -
}
## Main execution
RPMFILE="$*"
sign_rpm
##############END ##############################
RPMPWD is the passphrase. It should be set in the enviroment before sign_rpm is being called.
Of course, before running this script GPG private/public keys must have been imported in GPG keyring and public key must have been imported in RPM database also.
Showing posts with label UNIX - Admin. Show all posts
Showing posts with label UNIX - Admin. Show all posts
Monday, June 21, 2010
Monday, September 29, 2008
Rcp issue
TERM: Undefined Variable error
This was because user was getting C shell by default. When one does an rsh/rcp the shell that gets assigned in that case is also C shell. While logging into Csh, it was trying to source .tcsh file (which had some errors) which was actually checking for TERM value and since it was not defined, the execution could not complete. Hence the error.
Remedy : Just removed .csh file and it started working.
Thursday, April 17, 2008
External editing of files in Unix - II
While playing around with ex, I found one another script which is using "ed" to edit the files without actually opening them. Lets say in a text file, you want to insert particular string "Sunday is a Holiday" before every line on which the word Monday is found. Here is how you can write .ed script.
#####SCRIPT BEGINS#####
#!/bin/sh
TERM=vt100
export TERM
ed -s $1 "<<"MYEOF >/dev/null
1
/Monday/
i
Sunday is a holiday
.
w
q
MYEOF
#
exit 0
#####SCRIPT ENDS#####
Run the script as
bash-2.05$./test.ed abc.txt
So many hidden gems there!
#####SCRIPT BEGINS#####
#!/bin/sh
TERM=vt100
export TERM
ed -s $1 "<<"MYEOF >/dev/null
1
/Monday/
i
Sunday is a holiday
.
w
q
MYEOF
#
exit 0
#####SCRIPT ENDS#####
Run the script as
bash-2.05$./test.ed abc.txt
So many hidden gems there!
External editing of the files in Unix
While debugging a build break, I came across some scripts which were strangely named with extension .ed. Just out of curiosity I opened one of them and I was taken aback by the contents. I just wondered to myself how the hell did I never knew this?
It was using ex (actually just a command line interface to vi), which I now realize is such a powerful tool to edit files without actually opening them in editor window one by one. Let me give you a small example of how to use it. That ease of use will demonstrate its awesome powers.
Lets say you have a file named, abc.txt. The contents of the file are
Solaris
Linux
Hpux
Aix
Windows
Now lets say you want to replace string Windows with Apple. You can write one script named replace.ed which will look something like this:
#####SCRIPT BEGINS#####
#!/bin/sh
TERM=vt100
export TERM
ex -s $1 "<<" MYEOF >/dev/null
set noignorecase
%s/Windows/Apple/g
.
w
q
MYEOF
#
exit 0
##### SCRIPT ENDS#####
Now, all you have to do is to run the script by providing the file to be edited as an input.
bash-2.05$./replace.ed abc.txt
The utility example that I have displayed here is pretty simple, but surely good enough to emphasize the power of this tool. Just imagine how quickly and automatically you can do search and replace text for n number of files by calling this script from some iterative loop.
Happy Editing!
It was using ex (actually just a command line interface to vi), which I now realize is such a powerful tool to edit files without actually opening them in editor window one by one. Let me give you a small example of how to use it. That ease of use will demonstrate its awesome powers.
Lets say you have a file named, abc.txt. The contents of the file are
Solaris
Linux
Hpux
Aix
Windows
Now lets say you want to replace string Windows with Apple. You can write one script named replace.ed which will look something like this:
#####SCRIPT BEGINS#####
#!/bin/sh
TERM=vt100
export TERM
ex -s $1 "<<" MYEOF >
set noignorecase
%s/Windows/Apple/g
.
w
q
MYEOF
#
exit 0
##### SCRIPT ENDS#####
Now, all you have to do is to run the script by providing the file to be edited as an input.
bash-2.05$./replace.ed abc.txt
The utility example that I have displayed here is pretty simple, but surely good enough to emphasize the power of this tool. Just imagine how quickly and automatically you can do search and replace text for n number of files by calling this script from some iterative loop.
Happy Editing!
Thursday, January 10, 2008
Memory usage report for Unix system
Following simple script will generate the report of memory usage on unix system. It will store user memory, system memory and total memory consumption numbers in the report file, mem_stat.txt
##### SCRIPT BEGIN ########
#!/bin/sh
rm -rf /tmp/mem_stat.txt
top -f /tmp/mem.txt
while [ 1 ]
do
top -f /tmp/mem.txt;
grep Memory /tmp/mem.txt awk -F" " '{print $2,$5,$8}' sed -e 's/K//g' >> /tmp/mem_stat.txt;
rm -f /tmp/mem.txt;
sleep 30;
done>> /tmp/mem_stat.txt;
rm -f /tmp/mem.txt
########SCRIPT END#########
##### SCRIPT BEGIN ########
#!/bin/sh
rm -rf /tmp/mem_stat.txt
top -f /tmp/mem.txt
while [ 1 ]
do
top -f /tmp/mem.txt;
grep Memory /tmp/mem.txt awk -F" " '{print $2,$5,$8}' sed -e 's/K//g' >> /tmp/mem_stat.txt;
rm -f /tmp/mem.txt;
sleep 30;
done>> /tmp/mem_stat.txt;
rm -f /tmp/mem.txt
########SCRIPT END#########
Thursday, December 20, 2007
Library Path Variables
If some Unix application is crashing because it did not find some dependant library, you need to add the path of library file to standary library search path for Unix.
If /usr/foo/bar is the lcoation where you have the dependant library file available, then this is how you can add it to standard library for different OS's (assumming you are in bash shell):
Solaris & Linux:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/foo/bar
Aix:
export LIBPATH=$LIBPATH:/usr/foo/bar
HPUX:
export SHLIB_PATH=$SHLIB_PATH:/usr/foo/bar
If /usr/foo/bar is the lcoation where you have the dependant library file available, then this is how you can add it to standard library for different OS's (assumming you are in bash shell):
Solaris & Linux:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/foo/bar
Aix:
export LIBPATH=$LIBPATH:/usr/foo/bar
HPUX:
export SHLIB_PATH=$SHLIB_PATH:/usr/foo/bar
Monday, December 3, 2007
Rsh configuration
Requirement : User abc should be able to do an rsh and execute command on remote linux machine foo.bar.com from myfoo.bar.com
Solution : (Ideally first 3 steps should be enough to setup rsh execution. Please continue with steps 4 onwards to dig more.)
1. Create .rhosts file in user home directory.
2. Add following entries in it
foo.bar.com abc
myfoo.bar.com abc
3. Edit /etc/hosts.equiv (create new if it does not exist already) file to add entries
foo.bar.com abc
myfoo.bar.com abc
4. Edit /etc/securetty to have following entries
rsh
rlogin
rexec
rsync
5. Make sure that disable=no is set for following scripts in /etc/xinetd.d
rlogin
rsh
rexec
Solution : (Ideally first 3 steps should be enough to setup rsh execution. Please continue with steps 4 onwards to dig more.)
1. Create .rhosts file in user home directory.
2. Add following entries in it
foo.bar.com abc
myfoo.bar.com abc
3. Edit /etc/hosts.equiv (create new if it does not exist already) file to add entries
foo.bar.com abc
myfoo.bar.com abc
4. Edit /etc/securetty to have following entries
rsh
rlogin
rexec
rsync
5. Make sure that disable=no is set for following scripts in /etc/xinetd.d
rlogin
rsh
rexec
Subscribe to:
Posts (Atom)