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

понедельник, 8 апреля 2013 г.

Compiling kernel 3.4 on debian wheezy

sudo apt-get install kernel-package fakeroot build-essential


mkdir ~/tmp
cd ~/tmp
wget http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.4.tar.bz2
tar xvf linux-3.4.tar.bz2
cd linux-3.4/
cat /boot/config-`uname -r`>.config
make oldconfig

If your current kernel is 3.3.5 the questions that await are given at the bottom of this post with links to descriptions of the different options. As usual, if in doubt, just hit enter.

make-kpkg clean

Building takes ages (depending on number of cores committed), so don't launch it at 4 pm on a Friday if you need to shut down your computer before going home... As usual, use the -jX switch for parallel builds, where X is the number of cores+1 (i.e. 4 cores => -j5)

The following command goes on a single line
time fakeroot make-kpkg -j5 --initrd --revision=3.4.0 --append-to-version=-amd64 kernel_image kernel_headers

Once the build is done, move the .deb files out of the way and to your linux-3.4 directory for safe-keeping
 mv ../*3.4.0*.deb .
sudo dpkg -i *.deb
(c) from here

пятница, 18 ноября 2011 г.

bash howto's 3


#This will remove leading spaces...
echo " 1233 test " | sed 's/^ *//g'
#This will remove trailing spaces...
echo " test 543453 " | sed 's/ *$//g'


#Make the following XML file available under http://127.0.0.1:5555/
(printf "HTTP/1.1 200 OK\\r\\nContent-Type: text/xml\\r\\n"; \
printf "Content-Length: $(cat "response.xml"|wc -c)\\r\\n\\r\\n"; \
cat response.xml") | nc -l -p 5555 >/dev/zero 2>&1 &

понедельник, 14 ноября 2011 г.

пятница, 23 сентября 2011 г.

bash howto's 2

#extract from tar.xz
tar -xpJf archive.tar.xz

#setup environment variable
export VAR_NAME="value"
#somewhere use it
VAR_NAME=${VAR_NAME:-"default value"}
echo "$VAR_NAME"

#Запуск команд от имени системных пользователей
#Иногда требуется запустить некую команду, программу или просто проверить права #доступа от имени системных пользователей nobody, apache, и т.д. Простой запуск через
#su - nobody
#Даёт
#This account is currently not available.
#Это происходит из-за того, что у этих пользователей в качестве шела указан /sbin/nologin. #Можно воспользоваться параметром -s для указания другого шела:
su - nobody -s /bin/sh
#И получить нужный результат.

#how to list all disk drives ?
fdisk -l

#Copy a directory (and subdirectories) without .svn files.
rsync -a --exclude=.svn source destination

#Copy directory structure (without files)
find /where/to/search -type d | cpio -pvdm /where/to/copy

#find string in files
grep -lir "qwe"
grep -lir "mod.*" ./log*
find ./ -name log* -exec grep -l qwe {} \;

#bash filename extraction
FILENAME="/some/path/my.file.ext"
echo "Path: ${FILENAME%/*}"
echo "Filename: ${FILENAME##*/}"
echo "Extension: ${FILENAME##*.}"
BASENAME=${FILENAME##*/}
echo "Filename w/o extension: ${BASENAME%.*}"

#find the ten biggest files on your file system linux command
du -a /var | sort -n -r | head -n 10

#Show disk usage under Linux for folder
du -h -s /some/folder/path/*

# delete empty lines
sed "/^$/d" input
# remove spaces
sed 's/ //g'
# remove newline chars
sed 's/\n//g'

# search and replace
sed "s/searchpattern/replacepattern/" input

# find commandline options using sed and grep
URL=$(echo $@ | sed 's:\ :\n:g' | grep "url" | sed 's:\-\-url=::')

#Random string
openssl rand -base64 30

#Returns a list of the number of connections by IP.
netstat -an | grep :80 | awk '{print $5}' | cut -f1 -d":" | sort | uniq -c | sort -n
#Print out a list of open connections on your box and sorts them by according to IP address
netstat -atun | awk '{print $5}' | cut -d: -f1 | sed -e '/^$/d' |sort | uniq -c | sort -n
#Print the number of established and listening connections to your server on port 80 per each IP address
netstat -plan|grep :80|grep -E "(EST|LIST)"|awk {'print $5'}|cut -d: -f 1|sort|uniq -c|sort -nk 1

#Get Public IP and copy it to Clipboard
#!/bin/bash
MYIP=`curl -s 'http://checkip.dyndns.org' | sed 's/.*Current IP Address: \([0-9\.\.]*\).*/\1/g'`
echo $MYIP | pbcopy
/usr/local/bin/growlnotify 'IP address copied' -m "Address was: $MYIP"

#backup
sudo su
cd /
tar cvpjf /tmp/backup.tar.bz2 --exclude=/proc --exclude=/tmp --exclude=/dev --exclude=/lost+found --exclude=/backup.tar.bz2 --exclude=/mnt --exclude=/sys /

#http://www.catonmat.net/blog/sed-one-liners-explained-part-one/
#http://sed.sourceforge.net/sedfaq4.html
#http://sed.sourceforge.net/sed1line.txt
#http://tdistler.com/2009/04/17/sed-regular-expression-find-lines-not-matching-a-string
#Substitute (find and replace) only the last occurrence of "foo" with "bar".
sed 's/\(.*\)foo/\1bar/'
#Substitute all occurrences of "foo" with "bar" on all lines that DO NOT contain "baz".
sed '/baz/!s/foo/bar/g'
#Substitute all occurrences of "foo" with "bar" on all lines that contain "baz".
sed '/baz/s/foo/bar/g'

#extract language
cat $F | grep "Stream" | sed "s/ //g" | cut -f 1 -d ":" | sed "/.*(.*).*/!s/.*/und/g" | sed "s/^.*(\(.*\))$/\1/"

#echo full path to command
echo $0
echo "$0" | sed "s|^./|$(pwd)/|"
which ffmpeg
which ffmpeg | sed "s|^./|$(pwd)/|"

#/usr/local/bin/get-ip-address
/sbin/ifconfig | grep "inet addr" | grep -v "127.0.0.1" | awk '{ print $2 }' | awk -F: '{ print $2 }'

четверг, 25 августа 2011 г.

Как рекурсивно поменять права только каталогам или только файлам

cd /home/some_dir
chmod -R 644 *
find . -type d -exec chmod 0755 {} ';'

#Эта команда рекурсивно пройдется по текущему (точка ".") каталогу и всем его подкаталогам и изменит права на 755 только у каталогов (-type d)
find . -type d -exec chmod 755 {} \;
#Похожим образом действуем и с файлами:
find . -type f -exec chmod 644 {} \;
#если необходимо применить действия только к определенным файлам, подходящим по маске, то действуем так:
find . -type f -name '*.htm*' -exec chmod 644 {} \;
#а если нужно применить команду только к файлам или каталогам определенного владельца, то -
fiind . -type d -user fileowner -exec chmod 0755 {} \;

четверг, 18 августа 2011 г.

bash howto's

first line:
#!/bin/bash

#input parameters count:
$#

#script parameters:
$0 - self name, $1 ... $9 - input params

#check that file exist, the spaces near "[" and "]" are required :
if [ -e "streamcount.info" ]
then
echo 'file exist info'
fi

#get file extension:
SHORTFILENAME=$(basename $FULLFILENAME)
DEST_EXT=${SHORTFILENAME##*.}

#get temporary file name:
TFILE="/tmp/streaminfo.$RANDOM.$$.tmp"

#working directory:
$PWD

#redirect error stream to console and filter strings that contain word "Stream":
ffmpeg -i "$SRC" 2>&1 | grep "Stream"
#count strings with grep -c and put it into variable:
a=$( cat < $TFILE | grep -c "Audio:" )

#save command result as array with ( $( ) ):
s=( $( cat < $TFILE | grep "Audio:" | cut -f 2 -d "#" | cut -f 1 -d "(" ) )

#print array contents:
echo "stream numbers: ${s[@]:0}"

#use "for" construction:
for i in `seq 2 $a`;
do
index=$( echo "$i-1" | bc )
v="${s[index]}"
echo "$i. $v"
done

#extract float value:
x=$( echo "qwerty: 123.123123 !" | sed "s/.*[^0-9]\([0-9]\.[0-9]*\).*/\1/g" )

#float point operations:
echo "(256 / $x) / 10" | bc
for float result:
bc -l


# Checks for root privileges
if [ "$(whoami)" != 'root' ]
then
echo "You need to be root to execute uphosts. Exiting!"
exit 1
fi

# Checks required packages
ABORT=0
builtin type -P wget &>/dev/null || { echo -n "wget is missing."; ABORT=1; }
builtin type -P unzip &>/dev/null || { echo -n "unzip is missing."; ABORT=1; }
builtin type -P fromdos &>/dev/null || { echo -n "fromdos(tofrodos) is missing."; ABORT=1; }
builtin type -P grep &>/dev/null || { echo -n "grep is missing."; ABORT=1; }
if [ $ABORT != 0 ]
then
echo " Exiting!"
exit 2
fi