Wednesday, July 11, 2007

Rename multiple files in Linux

khob, 3 ta file daram ke extension nadaran :

# ls
file1 file2 file3

hala mikham be har 3 ta extension e ".rm" ezafe konam :

# for F in $(ls);do mv $F $F.rm;done
# ls
file1.rm file2.rm file3.rm

ba'd mikham extension e har 3 ta ro az ".rm" be ".mp3" taghiir bedam :

# for F in $(ls);do mv $F $(echo $F|sed -e 's,\.rm,,').mp3 ;done
# ls
file1.mp3 file2.mp3 file3.mp3

va belakhare mikham ke extension e har 3 ta ro hazf konam :

# for F in $(ls);do mv $F $(echo $F|sed -e 's,\.mp3,,') ;done
# ls
file1 file2 file3


hamin .... :">

Wednesday, June 13, 2007

SSH Tunneling



Nemidunam emruz chera man inghad SSH zade shodam, aslan hala ke injur shod, be kurie cheshme ajnabi, man emruzo ruze jahani e SSH elaam mikonam......

khob..... dastan az in gharare :
1- ye windows daram khune ke rush "PuTTY" daram. (172.16.20.254)
2- ye linux daram khune ke gateway e man e va rush sshd start shode. (invalid :172.16.20.1, valid: 21.22.23.24)
3- ye linux daram sherkat ke firewall e va sshd rush start shode, va be 21.22.23.24 ejaze mide ke ba ssh behesh vasl besham. (invalid: 192.168.1.1, valid:11.12.13.14)
4- ye station i hast sherkat ba ip e 192.168.1.10

avval farz mikonam ke station i sherkat hast linux e , mikham az station i ke khune hast ba ssh behesh connect sham:
1- ruye gatewaye khodam tu khune minevisam :

# ssh 11.12.13.14 -L 172.16.20.1:7000:192.168.1.10:22 -N

in yani in ke :
connect sho be firewall e sherkat (11.12.13.14), va port e 7000 ruye ip e invalid e khodet (172.16.20.1) ro map kon be port e 22 ruye 192.168.1.10 e un taraf.
-N yani inke haminjuri vaaysa hich kari nakon, faghat connection o negahdar.

2- hala az station e khune ba putty connect misham be port e 7000 e linux e khodam (172.16.20.1). (vali dar vaghe dare connect mishe be 192.168.1.10:22)

ajaaaaab shaaahkarie...... :-O


hala ye farze dige :
farz mikonam station i ke sherkat hast windows e va rush "PCAnyWhere" dare , ino bebin toro khoda...
1- ruye linux e khodam tu khune (172.16.20.1) minevisam :

# ssh 11.12.13.14 -L 172.16.20.1:5631:192.168.1.10:5631 -D 172.16.20.1:5632 -N

2- hala miram az windows e khune (172.16.2.254) ba "PCAnyWhere" ye connection misazam be linux e khodam tu khune (172.16.20.1) ( vali un dar vaghe dare connect mishe be 192.168.1.10)
-D yani 5632 ye port e "Dynamic" e ke bayad harvaght lazem shod ru 172.16.20.1 baaz beshe.

OhhOhhhhohhhhhhh, bavar kardani nist....

Tuesday, June 12, 2007

OpenSSH for Windows

packge i ke dar site http://sshwindows.sourceforge.net/ saakhte shode dar vaghe ye OpenSSH e minimal e ke dar cygwin ejra mishe , montaha ehtiaj be cygwin e kamel nadare.
ba in link download kardamesh : http://heanet.dl.sourceforge.net/sourceforge/sshwindows/setupssh381-20040709.zip
bad az unzip kardan o install kardan, config esh kardam :

C:\>cd "c:\Program Files\OpenSSH"
C:\Program Files\OpenSSH>cd bin
C:\Program Files\OpenSSH\bin>mkgroup -l >> ..\etc\group
C:\Program Files\OpenSSH\bin>mkpasswd -l -u Administrator > ..\etc\passwd
C:\Program Files\OpenSSH\bin>net start opensshd

khob windows e dige, labod bad az installation bayad ye bar restart ham beshe, jahhanam.

khob hala az ye linux behesh connect misham :

root@Slack:~# ssh Administrator@172.16.20.254

****USAGE WARNING****

This is a private computer system. This computer system, including all
related equipment, networks, and network devices (specifically including
Internet access) are provided only for authorized use. This computer system
may be monitored for all lawful purposes, including to ensure that its use
is authorized, for management of the system, to facilitate protection against
unauthorized access, and to verify security procedures, survivability, and
operational security. Monitoring includes active attacks by authorized entities
to test or verify the security of this system. During monitoring, information
may be examined, recorded, copied and used for authorized purposes. All
information, including personal information, placed or sent over this system
may be monitored.

Use of this computer system, authorized or unauthorized, constitutes consent
to monitoring of this system. Unauthorized use may subject you to criminal
prosecution. Evidence of unauthorized use collected during monitoring may be
used for administrative, criminal, or other adverse action. Use of this system
constitutes consent to monitoring for these purposes.


Administrator@172.16.20.254's password:
Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.

C:\Documents and Settings\Administrator>



mashalla ajab tam-taraaghi am dare .... ;)

hala ye test dige ba scp, masalan ye file o copy mikonam tu drive D:\mp3 :


root@172.16.20.254's password:
root@Slack:~# scp dela_didi.mp3 Administrator@172.16.20.254:/cygdrive/d/mp3

****USAGE WARNING****

This is a private computer system. This computer system, including all
related equipment, networks, and network devices (specifically including
Internet access) are provided only for authorized use. This computer system
may be monitored for all lawful purposes, including to ensure that its use
is authorized, for management of the system, to facilitate protection against
unauthorized access, and to verify security procedures, survivability, and
operational security. Monitoring includes active attacks by authorized entities
to test or verify the security of this system. During monitoring, information
may be examined, recorded, copied and used for authorized purposes. All
information, including personal information, placed or sent over this system
may be monitored.

Use of this computer system, authorized or unauthorized, constitutes consent
to monitoring of this system. Unauthorized use may subject you to criminal
prosecution. Evidence of unauthorized use collected during monitoring may be
used for administrative, criminal, or other adverse action. Use of this system
constitutes consent to monitoring for these purposes.


Administrator@172.16.20.254's password:
dela_didi.mp3 100% 13MB 733.6KB/s 00:18
root@Slack:~#


khob be salamti copy shod.....

man az in "USAGE WARNING" be khatere in rude derazi kardanesh aslan khosham nemiyaaaad ,.......khob hazfesh mikonam, naale nadare ke :


C:\>cd "c:\Program Files\OpenSSH"
C:\Program Files\OpenSSH>cd etc
C:\Program Files\OpenSSH\etc>edit sshd_config


bad miram un khatti ro ke ba kalameye "Banner" shuru mishe "hash mark"mizaram,
(ya be ghole yeki az bache ha : "PASH MARK" mizaram :)) ) , mishe in shekli :

#Banner /etc/banner.txt


bad service e opensshd o restart mikonam :

C:\Program Files\OpenSSH\etc>net stop opensshd
The OpenSSH Server service is stopping.
The OpenSSH Server service was stopped successfully.
C:\Program Files\OpenSSH\etc>net start opensshd
The OpenSSH Server service is starting.
The OpenSSH Server service was started successfully.


vaaaagheaaaan keeeeeeee, in pas chera restart nadare ???????????? =))
dar har hal ba stop/start kardan karam raah oftad.

hala test :


root@Slack:~# ssh Administrator@172.16.20.254
Administrator@172.16.20.254's password:
Last login: Wed Jun 13 09:16:07 2007 from 172.16.20.2
Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.

C:\Documents and Settings\Administrator>


Motshakkeram vaghean :">

Monday, May 28, 2007

Self-extracting Archive

baraye sakhte ye archive file ke ham auto-extract bashe, ham auto install, mishe az in ravesh estefade kard :
1- ehtiaj be ye file header darim :

#!/bin/sh

BLU='\E[1;34m'
RES='\E[0m'

echo ""
echo -e "${BLU} Self-Extracting ${RES} ..."
echo ""

# create a temp directory to extract to.
export WRKDIR=`mktemp -d /tmp/selfextract.XXXXXX`

SKIP=`awk '/^__ARCHIVE_FOLLOWS__/ { print NR + 1; exit 0; }' $0`

# Take the TGZ portion of this file and pipe it to tar.
tail +$SKIP $0 | tar xz -C $WRKDIR

# execute the installation script

PREV=`pwd`
cd $WRKDIR
./install.sh


# delete the temp files
cd $PREV
rm -rf $WRKDIR

echo ""
echo -e "${BLU} END ${RES} ..."
echo ""

exit 0

__ARCHIVE_FOLLOWS__


2- ehtiaj be ye file .tar.gz darim ke tush ./install.sh vujud dashte bashe mesle in :

#!/bin/bash

RED='\E[1;31m'
GRN='\E[1;32m'
RES='\E[0m'

echo -e "${RED} Upgrade to BIND 9.4.1 (Slackware11.0) ${RES} "
echo -e "${GRN} Making Backup ${RES} ..."
cp /etc/named.conf .
cp -r /etc/rndc.key .
cp -r /var/named .
rm -rf ./named/named.run

echo -e "${GRN} Downloading Package ${RES} ..."
wget -nv http://ftp.isc.org/isc/bind9/9.4.1/bind-9.4.1.tar.gz

echo -e "${GRN} Decompressing Package ${RES} ..."
tar -zxf ./bind-9.4.1.tar.gz

echo -e "${GRN} Configuring Package ${RES} ..."
cd ./bind-9.4.1
./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var > /dev/null

echo -e "${GRN} Compiling Package ${RES} ..."
make > /dev/null

echo -e "${GRN} Removing Old Package ${RES} ..."
removepkg bind > /dev/null

echo -e "${GRN} Installing New Package ${RES} ..."
make install > /dev/null 2>&1
cd ..

echo -e "${GRN} Restoring Backup ${RES} ..."
mv ./named.conf /etc/named.conf
mv ./rndc.key /etc/rndc.key
rm -rf /var/named
mv ./named /var/
rm -rf ./bind-9.4.1

echo -e "${GRN} Cleaning Up ${RES} ..."
rm -rf bind-9.4.1.tar.gz

echo -e "${GRN} Restarting BIND ${RES} ..."
/etc/rc.d/rc.bind restart

echo -e "${RED} $(named -v) successfuly installed ${RES} "


3- bad mishe ba in dastur file e auto extract ro saakht :
# cat header file.tar.gz > newfile.sh
# chmod +x newfile.sh

Saturday, May 26, 2007

Ext3 Partition Format, Redhat 8.0

Emruz yeki az cache server ha hesabi adaa dar avord;
raahi gheir az in nadashtam :

# mke2fs -cvj -L "/storage" /dev/sda5

BIND 9.4.1 - Slackware 11.0

"Bind-9.3.2-P1" ke tu "slackware 11.0" hast bug dare ve ye seri site haro resolve nemikone, ba update kardanesh be "BIND 9.4.1" moshkelesh hal shod.
az in script baraye update kardanesh estefade kardam :



#!/bin/bash

RED='\E[1;31m'
GRN='\E[1;32m'
RES='\E[0m'

echo -e "${RED} Upgrade to BIND 9.4.1 (Slackware11.0) ${RES} "
echo -e "${GRN} Making Backup ${RES} ..."
cp /etc/named.conf .
cp -r /etc/rndc.key .
cp -r /var/named .
rm -rf ./named/named.run

echo -e "${GRN} Downloading Package ${RES} ..."
wget -nv http://ftp.isc.org/isc/bind9/9.4.1/bind-9.4.1.tar.gz

echo -e "${GRN} Decompressing Package ${RES} ..."
tar -zxf ./bind-9.4.1.tar.gz

echo -e "${GRN} Configuring Package ${RES} ..."
cd ./bind-9.4.1
./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var > /dev/null

echo -e "${GRN} Compiling Package ${RES} ..."
make > /dev/null

echo -e "${GRN} Removing Old Package ${RES} ..."
removepkg bind > /dev/null

echo -e "${GRN} Installing New Package ${RES} ..."
make install > /dev/null 2>&1
cd ..

echo -e "${GRN} Restoring Backup ${RES} ..."
mv ./named.conf /etc/named.conf
mv ./rndc.key /etc/rndc.key
rm -rf /var/named
mv ./named /var/
rm -rf ./bind-9.4.1

echo -e "${GRN} Cleaning Up ${RES} ..."
rm -rf bind-9.4.1.tar.gz

echo -e "${GRN} Restarting BIND ${RES} ..."
/etc/rc.d/rc.bind restart

echo -e "${RED} $(named -v) successfuly installed ${RES} "