Linux 4 All

Best Linux tricks source

Posts in the script category

A nice MySQL query to get all FTP users and passwords from Plesk:

# mysql -u admin -p$(cat /etc/psa/.psa.shadow) -D psa
SELECT REPLACE(sys_users.home,'/home/http/vhosts/','') AS domain,
sys_users.login, accounts.password
FROM sys_users
LEFT JOIN accounts on
ORDER BY sys_users.home ASC;

A small and simple script to get users from a RHEL/CentOS box. It assumes that first UID is 500 and it won’t go beyond UID 999

1. Get all users

awk -F ":"  '$3>=500 && $3<1000  {print $1}' /etc/passwd

2. Get users with valid shell.

awk -F ":"  '($3>=500 && $3<1000) && ($7 ~ /sh/) {print $1,$7}' /etc/passwd

3. Get ftp users

awk -F ":"  '($3>=500 && $3<1000) && ($7 !~ /sh/) {print $1,$7}' /etc/passwd

For this, we are going to use egrep with -o option to print only the matched parts and not the entire line.

-o, –only-matching
Print only the matched (non-empty) parts of a matching line, with each such part on a separate output line.

Below there are 2 examples:

egrep -o "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}" $LOGFILE
egrep -o "([0-9]{1,3}\.){3}[0-9]{1,3}" $LOGFILE