Script to pull user name from password file

Script to pull user name from password file

root@node1:~# cat /etc/passwd |awk -F:  ‘{print $1}’
root
daemon
bin
sys
sync
games
man
lp
mail
news
uucp
proxy
www-data
backup
list
irc
gnats
nobody
systemd-timesync
systemd-network
systemd-resolve
systemd-bus-proxy
syslog
_apt
lxd
messagebus
uuidd
dnsmasq
sshd
ubuntu
ansible
test
user1

 

root@node1:~# cat /etc/passwd | cut -d : -f 1
root
daemon
bin
sys
sync
games
man
lp
mail
news
uucp
proxy
www-data
backup
list
irc
gnats
nobody
systemd-timesync
systemd-network
systemd-resolve
systemd-bus-proxy
syslog
_apt
lxd
messagebus
uuidd
dnsmasq
sshd
ubuntu
ansible
test
user1

Bash script to copy data on multiple servers

Script to copy data on multiple servers via shell script .In this Procedure we have 4 servers and where node 1 is the source servers and node 2 ,node 3 and node 4 are target servers.

1.Create a   file  containing all hosts.

# cat  servers
node2.mylabserver.com
node3.mylabserver.com
node4.mylabserver.com

2.Check the file which we need to copy to multiple servers.

# cat  file

This file will be copied from node1 to node 2,node3 and node4

[test@node1 ~]$

3. Script to copy the file

# for i in `cat servers`
do scp file "$i":/tmp/
done
file                                          100%   59    36.4KB/s   00:00
file                                          100%   59    40.0KB/s   00:00
file                                          100%   59    37.0KB/s   00:00

Note: servers are using password less authentication via ssh-key-gen

4. Check all servers there we will have copied data .

find nslookup for multiple servers via script

Steps to find nslookup for multiple servers 

1. store the server name in a file  named file1.txt  which located in /tmp/file1.txt

#cat file1.txt
Server01
Server02
Server03
Server04
Server05
Server06
Server07

2. run for loop to find the nslookup , Please run the commands as it is .

OracleServer01:# for i in `cat /tmp/file1.txt`;
do
nslookup $i
done

zip old /rotated logs in /var/log/messages file

#!/bin/bash
a=`find /var/log -name “messages.*” | grep -v gz | wc -l`
for (( i=0; i < $a; i++ ))
do
gzip -9 /var/log/messages.$i
done
ls -l /var/log/messages.*
find /var/log/ -type f -mtime +20 |grep -v *.gz | xargs rm -rf;

Unixplanetyary:# pwd
/var/log
Unixplanetyary#ls -ltr

-rw-r–r– 1 root adm 852480575 Jul 22 03:10 messages.9
-rw-r–r– 1 root adm 764759357 Jul 23 03:10 messages.8
-rw-r–r– 1 root adm 789044462 Jul 24 03:10 messages.7
-rw-r–r– 1 root adm 806885073 Jul 25 03:10 messages.6
-rw-r–r– 1 root adm 780612046 Jul 26 03:10 messages.5
-rw-r–r– 1 root adm 783171853 Jul 27 03:10 messages.4
-rw-r–r– 1 root adm 763277130 Jul 28 03:10 messages.3
-rw-r–r– 1 root adm 771602943 Jul 29 03:10 messages.2
-rw-r–r– 1 root adm 743181051 Jul 30 03:10 messages.1
-rw-r–r– 1 root adm 787018409 Jul 31 03:10 messages.0
-rw-r–r– 1 root adm 123195835 Jul 31 06:49 messgaes

After applying script output will be like this :

-rw-r–r– 1 root adm 448441364 Jan 9 03:10 messages.1.gz
-rw-r–r– 1 root adm 448886532 Jan 10 03:10 messages.0.gz
-rw-r–r– 1 root adm 9105430966 Jan 10 07:31 messages