Поиск по этому блогу

Показаны сообщения с ярлыком bash. Показать все сообщения
Показаны сообщения с ярлыком bash. Показать все сообщения

среда, 9 декабря 2015 г.

agony of some engineer

Yep, this is real =)
filename, username and IP address were changed. I found this when checked out bash history during daily activity.

 Check out bash history:
#1416529261
scp /path/to/file/file.log.bz2 someuser@localhost
#1416529302
scp /path/to/file/file.log.bz2  > /localhost/
#1416529315
scp /path/to/file/file.log.bz2  > /localhost/C:/
#1416529337
scp /path/to/file/file.log.bz2  > /localhost/user/someuser
#1416529395
scp /path/to/file/file.log.bz2  someuser@127.0.0.1
#1416529430
scp /path/to/file/file.log.bz2  someuser@127.0.0.1 /home/someuser
#1416529455
scp /path/to/file/file.log.bz2  someuser@127.0.0.1 /home/someuser/file
#1416529495
scp /path/to/file/file.log.bz2  someuser@127.0.0.1/home/someuser/file
#1416529502
scp /path/to/file/file.log.bz2  someuser@127.0.0.1/home/someuser/file/





пятница, 4 декабря 2015 г.

Extracting DB dump from archive with multiple DBs

Hello.

Today I'm going to explain how to extract mysql DB dump from a file with multiple DBs. Some time ago I used sed command to perform such tasks, but this method has some problems:

Let me show how to do this with sed:

cat/bzcat /path/to/file | sed -n '/^USE `DB_TO_RESTORE`/,/^USE /p'

to resotore TABLE_TO_RESTORE  table:
cat/bzcat /path/to/file | sed -n '/^DROP TABLE IF EXISTS `TABLE_TO_RESTORE`/,/^DROP TABLE IF EXISTS /p'

Or combine the commands above: =)

to restore DB_TO_RESTORE.TABLE_TO_RESTORE table:
cat/bzcat /path/to/file | sed -n '/^USE `DB_TO_RESTORE`/,/^USE /p' | | sed -n '/^DROP TABLE IF EXISTS `TABLE_TO_RESTORE`/,/^DROP TABLE IF EXISTS /p'

Problem with this method:
What about multiple mysql tables to restore with sed? Probably it is possible, but I'm not a sed hacker =)
What if /path/to/file is pretty big, sed will work until whole the file is processed, even if all needed data already restored...

To avoid this I created perl script that restores needed data and stops to process incoming data. Here you go: extractor.pl.

mysqldump commands will be printed to STDOUT, all information will be printed to STDERR.

Example:
cat dump.sql | extractor.pl DB table1 table2 > result.sql
db= DB, tables: table1 table2
DB # <- current="" db.="" nbsp="" p="">    table: XXX # <- current="" p="" table="">    table: XXXY
    table: ZZZZ
    table: DDD
    table: table1
    table: table2


Script stops working once it processed "DB" database.


Enjoy!






среда, 17 июня 2015 г.

single line bash script that kills all screen sessions

In continuation of previous post:
for n in `screen -ls | awk {'print $1'} | grep [0-9].\.. `; do screen -S $n -X quit; done

вторник, 16 июня 2015 г.

How to run command in screen tool and detach

I know that it could be googled, but I always forget this trick.

I'm going to run sleep 10 command.

It's pretty easy:
screen -dmS SCREEN_NAME
screen -S SCREEN_NAME -X stuff 'sleep 10'`echo -ne '\015'`

Note:
Of course someone could add comment that another way to run the command in screen is:
screen -dmS SCREEN_NAME "sleep 10"
I agree, but there is different behaviour: screen will be closed as soon as the command exited, that is why I have provided 2 commands, first one creates a screen, the second one runs sleep 10 command. You alway could attach to the screen and check out stdout/stderr.

среда, 18 сентября 2013 г.

sync files with tar over ssh

tar cfp  - `rsync -nv --files-from=filelist.txt /nas001/ localhost:/tmp/` --no-recursion  2>/dev/null | ssh localhost "cd /tmp/ && tar xfv -"

вторник, 10 сентября 2013 г.

How to send something via TCP using /dev/ in Linux

Small example below:

Now we starting listener on 8081 port:
nc -l 127.0.0.1 8081 &

We are going to send "1" to our listener:
echo 1 > /dev/tcp/127.0.0.1/8081
1 # We got it
[1]+  Done                    nc -l 127.0.0.1 8081


среда, 6 февраля 2013 г.

Just to remember


I always forget this simple command:
cat << EOF > rsync_files_to_nas.txt
bla bal bal
EOF


среда, 17 ноября 2010 г.

auto telnet bash script

Небольшой скрипт для автоматизации работы 

Полезный скрипт для автоматизации рутинной работы. Скрипт лезет по telnet  и выполняет определенный набор команд. Например если вам нужно обновить прошивку на 100 коммутаторах, эта штука вам подойдет. Набор команд находится в файле commands.
Короче говоря этот скрипт автоматизирует работу, и сам заходит по telnet и выполняет команды.

Сами команды находятся в файле 

[tsolodov@myserver ~/bin/conveer]$ cat ./commands
enable lldp
config lldp message_tx_interval 30
config lldp tx_delay 2
config lldp message_tx_hold_multiplier 4
config lldp reinit_delay 2
config lldp notification_interval 5
config lldp forward_message enable
config lldp ports 1-24 notification disable
config lldp ports 1-24 admin_status disable
config lldp ports 25-28 notification enable
config lldp ports 25-28 admin_status tx_and_rx
config lldp ports 25-28 basic_tlvs port_description system_name system_description system_capabilities enable
config lldp ports 25-28 dot1_tlv_pvid enable
config lldp ports 25-28 dot1_tlv_vlan_name vlanid 1-4094 enable
config lldp ports 25-28 dot1_tlv_protocol_identity eapol enable
config lldp ports 25-28 dot1_tlv_protocol_identity lacp enable
config lldp ports 25-28 dot1_tlv_protocol_identity gvrp enable
config lldp ports 25-28 dot1_tlv_protocol_identity stp enable
save


Вот сам скрипт:

[tsolodov@myserver ~/bin/conveer]$ cat ./conveer.sh
#!/usr/local/bin/bash
FILE=`cat $1 | sort -u` 
                 
for I in $FILE
  do
                 
 if [ -n "$I" ]
  then
 

(sleep 1; echo login_to_device; echo "password_to_device";sleep 2; cat ./commands; sleep 5; )| telnet $I                
 fi
done

параметр скрипта – путь с файлу с IP адресами в
Вот пример такого файла
[tsolodov @myserver ~/bin/conveer]$ cat ./ips
127.0.0.1
127.0.0.2


Вот и все, запускаем
[tsolodov@myserver ~/bin/conveer]$  ./conveer.sh ./ips
И на всех железяках будут выполнены команды как в файле ./commands