Tag: BASH

Bringing Cisco IOS CLI to Linux CLI

There are few people on the globe who loves to work with Cisco and Linux via CLI. These people might have issues with trying to apply Bash/Vim syntax to IOS and vice versa. I’m certainly one of them. That’s why I can do the followng in my Bash:

$ show .bashrc | i return
[[ "$-" != *i* ]] && return
#     return 0
#     [[ -z $adir ]] && return 1
#   [[ $? -ne 0 ]] && return 1
#     [[ $? -ne 0 ]] && return 0
#   return 0

It’s very handy for checking Cisco configs, stored on a Unix machines, without inverting your mind out. In fact, if you are in rush and tried to apply IOS syntax to Bash, you won’t be distracted by an error message, but you’d get a result you reqired.

$ show samle_conf.cfg | i spanning-tree
spanning-tree mode rapid-pvst
spanning-tree etherchannel guard misconfig
spanning-tree extend system-id
spanning-tree pathcost method long
 spanning-tree portfast
 spanning-tree portfast
 spanning-tree portfast
spanning-tree bpduguard enable
...

It’s achieved very easily. You need to add some aliases to your ~/.bashrc file and relogin:

echo 'alias show="cat"' >> ~/.bashrc
echo 'alias i="grep --color"' >> ~/.bashrc

Finding repeating lines in a text file

Today I learned how to find all repeating lines in a text file. My goal was to find out all lines in a text which repeat more than once. A dirty, but efficient way is using sort(8) and uniq(8) combination (thanks to my boss for a pointer).

$ sort /var/log/messages | uniq -d

Do not try to pass a file directly to uniq(8) unless it is sorted. Uniq(8) can find only adjacent equal lines. If you think lines are randomly dispersed throughout the file, uniq will not return correct result. Be careful.

Linux random passwords generation

This post is more a note to myself than a message I want to deliver to me struggling readers. There are two utilities for generating random passwords and one hack-around.

pwgen

Generates MANY passwords simultaneously. Very handy if somebody is behind your back watching you.

[root@hp ~]# pwgen
OVo4jiev Cohkah0r Iesev0ec thefuz0F asho6Zai em3tok5I Quoogh2k leeRuhi1
Eica7gie aew1ieTh Ukeewie3 Tee3aesa zasiCie7 iey9Ugho Eex5phae aip2ohHe
uL8AGee2 bux8rohX Aiv1voo2 AeS5thie uli1Shai aeWee0ai sha6aeV2 ni2Oong4
ahji7AiW rei0za9A uK1eih8a phoo4Aih taiGh0ab uod2ho8I tooX9coh jeeC5pie
ohxiCh7u oluif8Co OhTieC7e Phuro0sh eeca7Atu yee3Aeve Iwi1nige aiyu3Ein
AiCee0ba eC5Saehi voa2Aina ge4eiWee che8EeD2 Ait5ohth aQuahp4o oosou2Si
wa3aitiZ fah2oGhu do8oor5A Ied9Erob Caizei5a meeFai6b roh8WooW Lah8ieph
Eixoh6zi Cee8eidi eeChah6I eMohrij7 Zeisu0ha oech6Ae9 cioreT6p ee2Ohsha
Uu6yae5V zohShea8 Eizubo9r Reek2eiv Aak0veb7 phei3Ife onaeh7Oo jaiMopi9
Phohm9vi Ai3EeYie aequeeN8 eCiug9ei keiRee6I Aikei9wo tugh5Pae yie4maTu
eiH5Jei4 aeChia4I ahs3seeS eeg6Pa7M pei8Jooy ih1phiDu jee1ai4U uuY6eRai
wee5si4I ui2AhSoa Shee9EeB ahV4oof9 cei3pheZ iB5daw3u saegh4Lo Waroo1ah
aeth1Loo ohReesh4 Saidae7o meB7tha6 Eetae9Oh meiyiR5e AeTooc3c Bu0ou0se
Ahree5Of eiwuJie9 Cuogh7ae eekeeB8V ruu0Yoqu angie1Ki Oang3eeb Oobe9jiP
Loo3Oova yieNee0n moo2aiSh aem6ooD3 Paehoh2w xee6Ooph acahph2A kooGu5Ie
hag2Buon chah4Bii xaequ4In Ooy9Lohk oophoh4N Oo5Roh4a Phe8choo xa2Thoo4
XahBoo4j eeHah2ai Quaico6D Lauh0eiF Eiv9ga9c ih9pooPh aedeLaS3 ohleiGo2
aPh7wivi le4Xah9d lahl4Hei shu2Kuch OhfeDi7z Aengaej7 Phie4oom eige6Fae
Xaesh2Ju iN7Coh3S The8Ij4z kae0OGhi Shei6ohp RooReim6 Pheih3Ai Aikah8sh
taiph4Ei kaoRoh1f om0moh3S uaphee7E lab4Xu9k kahh3saZ ain8Zeic Uu1fohvo

apg

Generates few random passwords.

[root@hp ~]# apg
johebud6
VuwejThig1
TegtuIdNi
FlabEpNeec
bytjeewk
voyHatadd5

Unix hacker’s way.

This way is considered to be insecure, but Jesus! Who would know you have used this freaking way!

for ((n=0;n<10;n++)); do dd if=/dev/urandom count=1 2> /dev/null | base64 | sed -ne 2p | cut -c-8; done

Fast appending files to tar archive is impossible.

Eventually, tar is very slow for appending files to the existing tarball. I’m particularly talking about following options:

-r – append files to the end of an archive
-u – only append files newer than copy in archive

Logically thinking, for -u to work, it should accomplish linear search through the archive. Than bigger the archive, than slower the search. Moreover, if you’ll try to append in the loop, it will accomplish search as many times as many iterations you loop has. I would advice to use in the most exceptional case ONLY. Try avoiding

# -u. slow inefficient approach of taring multiple files
for file in $(ls -A)
do
    tar -uf tarball.tar $file;		#traverses all archive to append the file.
done

You’d think that -r option usage forces tar application to append files to the end of the archive, getting the position of the archive’s end from archive’s index. It doesn’t. Tar format is designed in a way that it has no index.

# -r approach is also slow and inefficient
for file in $(ls -A)
do
    tar -rf tarball.tar $file;		#traverses all archive to append the file.
done

However, TAR supports several formats for its archive. But they are not well-documented. I had a brief overview of them, and looks like
–format=gnu is the most recent and featured one. And It still has no index. I no longer understand why tar is even used. Despite of that, below is a workaround, allowing for packing unlimited amounts of files right instant. I recommend to never use append function with tar format. Instead, get to know what are you going to archive, prepare necessary files, and archive them all.

# faster approach for taring multiple files. No appending
ls -A >> list.txt
tar -cT list.txt -f backup.tar

Linux Terminal (BASH) Keyboard shortcuts. Readable presentation.

Linux terminal shortcuts are extremely handy. They can speed-up your everyday tasks significantly. Additionally, most commends are applicable to Cisco telnet/SSH sessions and any other terminals. A very little amount of people aware that your terminal can cut/paste strings and words. It can, all shortcuts are there.

There are thousands of pages out there with the list of same shortcuts. What is the reason for me to duplicate widely spread information? Simple – all list around there are organized in a random unreadable way. I’ve put some effort and organized stuff according the functionality. I believe that my version of the list is much more usable than the rest out there. Enjoy.

Read More »

Fedora 10 Proprietary Soft Installation Script

When I Migrated to Fedora 10, I wrote small script, which was installing most common proprietary software I needed and updates system. I didn’t publish it, because I thought that it is useless and “do not publish all crap you think matters”. But this script was used more than twice by me, so Here it is. Just run it as Root.

su -c '
#Installing proprietary repositories
#rpm fusion
rpm -Uvh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm;
#adobe
rpm -ivh http://linuxdownload.adobe.com/adobe-release/adobe-release-i386-1.0-1.noarch.rpm;
#installing software
yum -y install  kmod-nvidia stardict fusion-icon flash-plugin gnome-mplayer audacity xine-lib-extras-nonfree vlc libdvdread gstreamer-plugins* libmad libid3tag id3v2 xine-lib-extras-nonfree kdemultimedia-extras-nonfree wine unrar ida stardict azureus;
#updating sustem
yum -y update;
#healing fedora-after-update-bug
rm -rf /var/lib/rpm/__db.*;
'

UPDATE: I was pointed to a more robust script for additional soft installation for fedora.FedoMATIX