-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbashrc-remote
executable file
·121 lines (111 loc) · 6.09 KB
/
bashrc-remote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/bash
##################################################################
# bashrc-remote for use with remotebashrc.sh
# Created by: Justyn Shull <[email protected]>
#
# Last Updated: 12/02/2009
#
# If you see this file in your /tmp folder, don't worry. It's safe
# visit http://www.justynshull.com/project/remotebashrc.html for info
############### Setup some enviroment variables and bash options
#Test..
#source server bashrc before anything else
[ -f ~/.bashrc ] && source ~/.bashrc
shopt -s checkwinsize
shopt -s histappend
#define some colors to make things pretty later
red="\033[01;31m";
green="\033[01;32m";
############### Export the PS1 prompt style and PATH. Display motd if it exists (for managed servers)
#export PS1="\[\033[01;32m\][\u@\h\[\033[01;34m\] \w ]$\[\033[00m\]"
[ ${UID} -eq 0 ] && PROMPT_COLOR="\[\033[01;31m\]" || PROMPT_COLOR="\[\033[01;32m\]"
export PS1="$PROMPT_COLOR\h\[\033[01;34m\] \W \$ \[\033[00m\]"
export PATH="$PATH:/usr/local/psa/admin/bin/:/sbin/:/usr/sbin/"
[ -f /etc/motd ] && cat /etc/motd;
############### Standard-ish Aliases
alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -i'
alias ll='ls -l'
alias lla='ls -la'
alias llah='ls -lah'
alias :q='exit'
alias :wq='exit'
alias :q!='kill -9 $$'
alias grep='grep --color=auto'
alias c='clear'
[ -x /usr/local/bin/gnuls ] && alias ls="gnuls --color=auto" || alias ls='ls --color=auto'
############## Not so standard Aliases
#pipe the output of a command to sprunge and it will give you a link to a paste-bin type page
#add ?php or ?sh or etc to have it add line numbers and highlighting
alias sprunge="curl -F 'sprunge=<-' http://sprunge.us"
#automatically resume scp transfers that failed or paused
alias scpresume='rsync --partial --progress --rsh=ssh'
#makes a directory tree listing
alias dirtree='find . -type d | sed -e "s/[^-][^\/]*\// |/g" -e "s/|\([^ ]\)/|-\1/"'
#alias I made to strip comments from a bash or php script. May need tweaked still
alias stripcomments="sed -e '/^[[:blank:]]*#/d; s/[[:blank:]][[:blank:]]*#.*//' -e '/^$/d' -e '/^\/\/.*/d' -e '/^\/\*/d;/^ \* /d;/^ \*\//d'"
#phpinfo_e > info.php (write a basic phpinfo() file for testing)
alias phpinfo_e="echo '<?php phpinfo(); ?>'";
#alias vim to vi if vim isn't installed
[ ! -x /usr/bin/vim ] && alias vim="vi" && echo -e "$red vim is not installed.\e[m aliasing vim to vi" || alias vi="vim";
############## Plesk Aliases
## These will only get set if .psa.shadow exists on the system.
if [ -f /etc/psa/.psa.shadow ]
then
#assume this is a plesk machine
echo -e "$red psa.shadow $green \e[m found. Assuming plesk is installed";
alias plesk_pass="cat /etc/psa/.psa.shadow";
alias plesk_mailusers="mysql -uadmin -p`cat /etc/psa/.psa.shadow ` psa -e 'select m.mail_name,a.password,d.name from mail m,accounts a,domains d where m.account_id=a.id and m.dom_id=d.id;'";
alias plesk_ftpusers="mysql -uadmin -p`cat /etc/psa/.psa.shadow` -N psa -e 'select s.login,s.home,a.password from sys_users s,accounts a where s.account_id=a.id;'";
alias plesk_dbusers="mysql -u admin -p`cat /etc/psa/.psa.shadow` psa -e 'select u.login,a.password,b.name,d.name from db_users u,accounts a,data_bases b,domains d WHERE u.account_id=a.id AND u.db_id=b.id AND b.dom_id=d.id;'";
alias plesk_clients="mysql -u admin -p`cat /etc/psa/.psa.shadow` psa -e 'select s.login,a.password from clients s,accounts a where s.account_id=a.id;'";
alias plesk_mysql="mysql -u admin -p`cat /etc/psa/.psa.shadow`";
alias plesk_regenhttpdconf="/usr/local/psa/admin/bin/websrvmng -av";
alias plesk_restartall="service psa stopall;service psa start";
else
echo -e "$red psa.shadow not found.\e[m";
fi
############# Custom functions and commands
genpasswd() {
local l=$1
[ "$l" == "" ] && l=20
tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${l} | xargs
}
#utime converts unix-time to ..normal time
utime(){ perl -e "print localtime($1).\"\n\"";}
whatismyip(){ wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'; }
#display top 10 cpu-using processes, and top 10 cpu-using users
topproc10(){ ps -eo pcpu,pmem,user,pid,cmd | sort -r | head -10; }
topproc10u() { ps -eo user,pcpu,pmem | tail -n +2 | awk '{num[$1]++; cpu[$1] += $2; mem[$1] += $3} END{printf("NPROC\tUSER\tCPU\tMEM\n"); for (user in cpu) printf("%d\t%s\t%.2f\t%.2f\n",num[user], user, cpu[user], mem[user]) }'; }
#test_site_speed times how long it takes to do a dns lookup and download a website
test_Site_speed() {
URL="${1}";
curl -L --w "$URL\nDNS %{time_namelookup}s conn %{time_connect}s time %{time_total}s\nSpeed %{speed_download}bps Size %{size_download}bytes\n" -o/dev/null -s $URL
}
#misc functions. should be self-explanitory
calc(){ awk "BEGIN{ print $* }" ;}
function check_ssl_date() { echo | openssl s_client -connect "${1}":443 2>/dev/null |openssl x509 -dates -noout; }
dh() { du -ch --max-depth=1 "${@-.}"|sort -h; }
##### new netstat2 function. Does some neat stuff with netstat
function netstat2() {
case "$1" in
"ipcount" )
netstat -nat | grep ":80" | awk -F: '{print $8}' | sort | uniq -c | sort -n;;
"top20" )
netstat -nat | grep ":80" | awk -F: '{print $8}' | sort | uniq -c | sort -n | awk '{ if ( $1 > 20 ) print $2 ; }';;
* )
echo "Run netstat2 with one of these commands:"
echo "ipcount: lists all of the ips connected to the server sorted by the number of connections they have open"
echo "top20: Same as above but only lists the top 20 and does not display the number of connections open per ip"
;;
esac;
}
############## Some useful things to know about the server when first connecting to it
echo -e "$green Uptime: $red `uptime` \e[m"
echo -e "$green Total procs: $red `ps aux | wc -l` \e[m"
services="httpd mysqld apache2 proftpd qmail-send master sendmail"
echo -ne "$green Services: \e[m";for serv in $services; do [ ! "$(pidof $serv)" ] && echo -ne "$serv:$red Off\e[m " || echo -ne "$serv:$green On\e[m "; done;echo ""
#Switch -vi to -fv if you don't want to be prompted to delete this file(potentially unsafe?)
#$BASH_SOURCE works but $0 won't work if you run 'source /tmp/bashrc'
rm -vi "$BASH_SOURCE";