Tuesday, June 18, 2013
UNIX/Linux script to set or update the password for multiple users
Example:
Sample users name: dummy1, dummy2, dummy3, dummy4 and dummy5
for counter in {1..5}; do echo "dummy$counter" | passwd dummy$counter --stdin ; done
NOTE: {1..5} syntax will not work in certain shell. But it will work definitely in bash.
UNIX/Linux Shell Script to delete multiple users
Example 1:
To delete the users: dummy1, dummy2, dummy3, dummy4 and dummy5
for counter in {1..5}; do userdel dummy$counter; done
It can also be written as,
for counter in {1..5}
do
userdel dummy$counter
done
NOTE: {1..5} syntax will not work in certain shell. But it will work definitely in bash.
Example 2:
cat > user.list
vijay
sanjay
ajay
sujay
for user in `cat user.list`;do userdel $user;done
UNIX/Linux Shell script to create multiple users
Example 1:
NOTE: {1..5} syntax will not work in certain shell. But it will work definitely in bash.
Example 2:
cat > user.list
vijay
sanjay
ajay
sujay
for user in `cat user.list`;do useradd $user;done
grep -i jay /etc/passwd | cut -d: -f1
vijay
sanjay
ajay
sujay
NOTE: {1..5} syntax will not work in certain shell. But it will work definitely in bash.
Example 2:
vijay
sanjay
ajay
sujay
for user in `cat user.list`;do useradd $user;done
grep -i jay /etc/passwd | cut -d: -f1
vijay
sanjay
ajay
sujay
Monday, June 10, 2013
How to grep recursively in Solaris?
In Solaris, Solaris grep will not provide recursive option -r to search a pattern recursively. But solaris provides another command called ggrep to search recursively. But ggrep location is normally not included in the PATH variable.
[vjsujay@cheetah:/home/vjsujay]$which ggrep
no ggrep in /usr/bin /bin /usr/sbin /sbin /usr/local/bin
[vjsujay@cheetah:/home/vjsujay]$ls -l /usr/sfw/bin/ggrep
-r-xr-xr-x 3 root bin 125664 Jan 23 2005 /usr/sfw/bin/ggrep
[vjsujay@cheetah:/home/vjsujay]$
Example for recursive grep using ggrep in Solaris:
[vjsujay@cheetah:/home/vjsujay/sp]$ /usr/sfw/bin/ggrep -R 'apple' *
file.txt:apple
file3.txt:apple orange
jsk/jsk.txt:apple
[vjsujay@cheetah:/home/vjsujay/sp]$
[vjsujay@cheetah:/home/vjsujay]$which ggrep
no ggrep in /usr/bin /bin /usr/sbin /sbin /usr/local/bin
[vjsujay@cheetah:/home/vjsujay]$ls -l /usr/sfw/bin/ggrep
-r-xr-xr-x 3 root bin 125664 Jan 23 2005 /usr/sfw/bin/ggrep
[vjsujay@cheetah:/home/vjsujay]$
Example for recursive grep using ggrep in Solaris:
[vjsujay@cheetah:/home/vjsujay/sp]$ /usr/sfw/bin/ggrep -R 'apple' *
file.txt:apple
file3.txt:apple orange
jsk/jsk.txt:apple
[vjsujay@cheetah:/home/vjsujay/sp]$
Subscribe to:
Posts (Atom)