Sometimes I want to FTP a file from one machine to another. Usually, I can do the transfer interactively, but every so often, I would like to have a shell script do the file transfer. This task has eluded me in the past, but I finally figured it out. I've not seen this particular trick documented in the past, so I submit it for your approval...
Архив тега ‘bash’
check webpage load time via wget (перепечатка)
Here is a simple one liner to check on download time of a webpage:
(time wget -p --no-cache --delete-after www.linuxweblog.com -q ) 2>&1 | awk '/real/ {print $2}'Domain searching with bash (перепечатка)
Below is a simple bash script that uses the dictionary to go through 3 letter words and does a whois check to see if the domain is available. You probably won't find any of those as all would have been taken. May want to try with 5 or 6 letters instead, in which case change the value of «$count».
#!/bin/bash<br /># domain_search.sh<br /><br /># Get a list of 3 letter domains.<br />for x in `cat /usr/share/dict/words`; do count=`echo $x| wc -m`; [ $count = 4 ] && echo $x; done > domains_list.txt<br /><br /># Get whois record. <br />for x in `cat ./domains_list.txt` ; do (whois $x.com | grep -q '^No match for domain') && echo $x; sleep 60; done > domains_available.txt<br /><br /># Change to lowercase and sort print.<br />cat domains_available.txt | tr [:upper:] [:lower:]|sort| uniqСкрипт синхронизации баз, сайтов и конфигов (перепечатка)
С помощью данного скрипта можно синхронизировать папки сайтов, базы MySQL и конфиги виртуал-хостов апача и nginx с одного сервера на другой. Синхронизация баз происходит без остановку мускула.
param=" --progress -plzuogthr --compress-level=9 --delete-after"
sitesfromserver1="site1.ru site2.ru site3.ru"
basesfromserver1="basesite1 basesite2 basesite3"
### Apache vhosts — Not need "update" parametr
rsync -e "ssh -p222" --progress -plzogthr --compress-level=9 --delete-after /etc/httpd/vhosts root@server2.domain.com:/etc/httpd
### Nginx vhosts — Not need "update" parametr
rsync -e "ssh -p222" --progress -plzogthr --compress-level=9 --delete-after /etc/nginx/vhosts root@server2.domain.com:/etc/nginx
### Sites sync
for site in $sitesfromserver1
do
rsync -e "ssh -p222" $param /usr/local/www/$site root@server2.domain.com:/usr/local/www
done
### MySQL bases sync
echo "Lock bases on Server1 and Server2"
echo "FLUSH TABLES WITH READ LOCK; SET GLOBAL read_only = ON;" | /usr/bin/mysql -u backup -pPasWord
ssh -p222 root@server2.domain.com 'echo "FLUSH TABLES WITH READ LOCK; SET GLOBAL read_only = ON;" | /usr/bin/mysql -u backup -pPasWord'
echo "Sleep 15s"
sleep 15s
# Bases from Server1
for base in $basesfromserver1
do
rsync -e "ssh -p222" $param /var/lib/mysql/$base root@server2.domain.com:/var/lib/mysql
done
echo "Unlock bases"
echo "SET GLOBAL read_only = OFF; UNLOCK TABLES;" | /usr/bin/mysql -u backup -pPasWord
ssh -p222 root@server2.domain.com 'echo "SET GLOBAL read_only = OFF; UNLOCK TABLES;" | /usr/bin/mysql -u backup -pPasWord'
ssh -p222 root@server2.domain.com /etc/init.d/mysqld restart
quickly check your mail server using telnet, mail or mutt (перепечатка)
There are of course various ways to check whether your mail server is now configured ok or not but what I found is that checking through telnet is quick and easy. let’s check our mail server now, it may be mail.youdomain.com or localhost depending on what you are using right now, here’s the full process: [...]
Clean up config files (перепечатка)
Below are one liners to clean out all comment and blank lines with grep and sed, usually in config files.
grep -v "^#\|^$" <conf_file>or
grep -v "^\#" <conf_file> | sed '/^$/d'Ensuring secure access to Production Linux Servers (перепечатка)
I was amazed to hear from my friend that one of their server got hacked and reason may be that their part-time admin set password of root user as ‘admin’. Wow!! can’t believe it! They dont have right to cry about security attacks as they themselves keep their door opens I’ve suggested them some points [...]
Bash script to backup essential log files of Linux Server (перепечатка)
Here’s small bash script to backup important log files from a server to a backup server. You should customize it per your environment. I’ve deployed this script in some hosts and its working fine for me but I’m not making any guarantee that this will work for you as well.
Task: Two most imporant log [...]
Detect directory or file changes in *nix (перепечатка)
There are various wasys to do this, but this is what I implemented. It is working as expected as of now on my RHEL 5.x boxes. I’ll take my usecase here and describe things.
Plesk web hosting control panel is managing several hundred domains on one of RHEL box. Addition and removal of domains is [...]
freebsd+screen+mc: read (subshell_pty…): Unknown error: 0 (0) (перепечатка)
Столкнулся с проблемой. Во FreeBSD под screen после отстрела mc новые экземпляры mc отказываются запускаться, выводя загадочное сообщение об ошибке:
read (subshell_pty...): Unknown error: 0 (0)
Похоже, проблема в том, что после отстрела mc остались процессы в состоянии STOP.
Воспроизвести глюк не удалось, поэтому привожу решение, которое помогло мне:
$ killall -CONT bash2
(посылаем CONT своему шеллу)
Ссылки по теме: