Portal Home > Knowledgebase > Articles Database > script to remove domains from /etc/userdomains to a file with all cPanel account name
script to remove domains from /etc/userdomains to a file with all cPanel account name
Posted by sharmaine1111, 08-16-2009, 11:42 PM |
can someone please help me how I can create a bash script to get all the cpanel account names from /etc/userdomains and save it in a file?
In same way, I would like to know how to create a bash script that will scan a directory for all .tar.gz file and get only the account names and save it to a file so I can create a script to mass restore the backups.
|
Posted by supportexpertz, 08-17-2009, 02:27 AM |
1) You can get the users account names from /var/cpanel/users . Run the below command
All the users will be listed under the file /root/user_list
Or from the file /etc/trueuserdomains as below :
2) Consider your backup is in the directory /backup/cpbackup/daily and its in the format
username.tar.gz
then you can follow
|
Posted by nomankhn, 08-17-2009, 02:35 AM |
cat /etc/userdomains | cut -d: -f2 > useraccount.txt
cat /etc/userdomains | cut -d: -f1 > domainlist.txt
|
Posted by sharmaine1111, 08-17-2009, 02:42 AM |
Thank you, what does this do:
|
Posted by supportexpertz, 08-17-2009, 02:58 AM |
awk is a pattern-matching program for processing files .
awk -F. '{print $1}' . is the limiter and it takes the field and print $1 gets the first field
if you do awk -F. '{print $2}' , it gets the second filed . so the output will be just "tar"
You can ofcourse get the result from cat /etc/userdomains , but note that duplication of account name can occur (from accounts subdomains ,parkdomains etc) . To get the unique usernames we may have to sort it. Since /etc/trueuserdomains and /var/cpanel/users gives unique results , you may follow that .
|
Posted by sharmaine1111, 08-17-2009, 03:04 AM |
Thanks, but what does this do:
what is sed?
|
Posted by supportexpertz, 08-17-2009, 03:13 AM |
It is also used to parse text files . Actually you needn't use that option sed 's/ //g'
What I was trying to do is , when you run just
cat /etc/trueuserdomains | awk -F: '{print $2}' > /root/user_list
and open the file /root/user_list , you can see a "space" before all the usernames . Just to avoid that i used sed .
|
Posted by sharmaine1111, 08-17-2009, 03:35 AM |
Thanks I get it now! You're such a big help!
|
Posted by writespeak, 08-17-2009, 11:14 AM |
Closed by request.
Lois
|
Add to Favourites Print this Article
Also Read