Omanila skripta

Poslao gigolo on 01.08.2010 18:19:35
Imam skriptu koju izvodim svaki dan u 17.00 preko krona. Evo je:

#!/bin/bash
mpg123 /home/davor/linux/bckp/zvk/gong.mp3
cp /home/davor/linux/bckp/slk/bckp.gif /home/davor/Desktop
cp /home/davor/linux/bckp/kad.txt /home/davor/linux/bckp/kad-old.txt
echo $(date) > /home/davor/linux/bckp/kad.txt
cd /media/bckp
echo "Backup"
mpg123 /home/davor/linux/bckp/zvk/apert.mp3
echo "Lekcije"
cp /home/davor/linux/bckp/slk/lkcj.gif /home/davor/Desktop
rm -fr Lekcije
cp /home/davor/Lekcije /media/bckp -R
rm /home/davor/Desktop/lkcj.gif
mpg123 /home/davor/linux/bckp/zvk/apert.mp3
echo "linux"
cp /home/davor/linux/bckp/slk/lnx.gif /home/davor/Desktop
rm -fr linux
cp /home/davor/linux /media/bckp -R
rm /home/davor/Desktop/lnx.gif
mpg123 /home/davor/linux/bckp/zvk/apert.mp3
echo "Razno"
cp /home/davor/linux/bckp/slk/rzn.gif /home/davor/Desktop
rm -fr Razno
cp /home/davor/Razno /media/bckp -R
rm /home/davor/Desktop/rzn.gif
mpg123 /home/davor/linux/bckp/zvk/apert.mp3
echo "Slike"
cp /home/davor/linux/bckp/slk/slk.gif /home/davor/Desktop
rm -fr Slike
cp /home/davor/Slike /media/bckp -R
rm /home/davor/Desktop/slk.gif
mpg123 /home/davor/linux/bckp/zvk/apert.mp3
echo "Web"
cp /home/davor/linux/bckp/slk/wb.gif /home/davor/Desktop
rm -fr Web
cp /home/davor/Web /media/bckp -R
rm /home/davor/Desktop/wb.gif
mpg123 /home/davor/linux/bckp/zvk/apert.mp3
echo "Obrada"
cp /home/davor/linux/bckp/slk/obr.gif /home/davor/Desktop
rm -fr Obrada
cp /home/davor/Obrada /media/bckp -R
rm /home/davor/Desktop/obr.gif
mpg123 /home/davor/linux/bckp/zvk/apert.mp3
echo "Spremi"
cp /home/davor/linux/bckp/slk/spr.gif /home/davor/Desktop
rm -fr Spremi
cp /home/davor/Spremi /media/bckp -R
rm /home/davor/Desktop/spr.gif
#echo "Download"
#cp /home/davor/linux/bckp/slk/dwn.gif /home/davor/Desktop
#rm -fr Download
#mkdir Download
#cp /home/davor/Download/00000 /media/bckp/Download -R
#cp /home/davor/Download/zzzzz /media/bckp/Download -R
#rm /home/davor/Desktop/dwn.gif
echo $(date) >> /home/davor/linux/bckp/kad.txt
rm /home/davor/Desktop/bckp.gif
echo "Gotovo"
a=`date | awk '{print $1}'`
if [ "$a" == "Sun" ]; then
cp /home/davor/linux/bckp/slk/bckp.gif /home/davor/Desktop
#zenity --notification --text=backup_počinje
cp /home/davor/linux/bckp/kad.txt /home/davor/linux/bckp/kad-old.txt
echo $(date) > /home/davor/linux/bckp/kad.txt
#sudo mount /dev/sdc1 /media/store
cd /media/store
echo "Backup"
mpg123 /home/davor/linux/bckp/zvk/apert.mp3
echo "Lekcije"
cp /home/davor/linux/bckp/slk/lkcj.gif /home/davor/Desktop
rm -fr Lekcije
cp /media/bckp/Lekcije /media/store -R
rm /home/davor/Desktop/lkcj.gif
mpg123 /home/davor/linux/bckp/zvk/apert.mp3
echo "linux"
cp /home/davor/linux/bckp/slk/lnx.gif /home/davor/Desktop
rm -fr linux
cp /media/bckp/linux /media/store -R
rm /home/davor/Desktop/lnx.gif
mpg123 /home/davor/linux/bckp/zvk/apert.mp3
echo "Razno"
cp /home/davor/linux/bckp/slk/rzn.gif /home/davor/Desktop
rm -fr Razno
cp /media/bckp/Razno /media/store -R
rm /home/davor/Desktop/rzn.gif
mpg123 /home/davor/linux/bckp/zvk/apert.mp3
echo "Slike"
cp /home/davor/linux/bckp/slk/slk.gif /home/davor/Desktop
rm -fr Slike
cp /media/bckp/Slike /media/store -R
rm /home/davor/Desktop/slk.gif
mpg123 /home/davor/linux/bckp/zvk/apert.mp3
echo "Web"
cp /home/davor/linux/bckp/slk/wb.gif /home/davor/Desktop
rm -fr Web
cp /media/bckp/Web /media/store -R
rm /home/davor/Desktop/wb.gif
mpg123 /home/davor/linux/bckp/zvk/apert.mp3
echo "Obrada"
cp /home/davor/linux/bckp/slk/obr.gif /home/davor/Desktop
rm -fr Obrada
cp /media/bckp/Obrada /media/store -R
rm /home/davor/Desktop/obr.gif
mpg123 /home/davor/linux/bckp/zvk/apert.mp3
echo "Spremi"
cp /home/davor/linux/bckp/slk/spr.gif /home/davor/Desktop
rm -fr Spremi
cp /media/bckp/Spremi /media/store -R
rm /home/davor/Desktop/spr.gif
#echo "Download"
#cp /home/davor/linux/bckp/slk/dwn.gif /home/davor/Desktop
#rm -fr Download
#mkdir Download
#cp /media/bckp/Download/00000 /media/store/Download -R
#cp /media/bckp/Download/zzzzz /media/store/Download -R
#rm /home/davor/Desktop/dwn.gif
echo $(date) >> /home/davor/linux/bckp/kad.txt
rm /home/davor/Desktop/bckp.gif
echo "Gotovo"
fi
mpg123 /home/davor/linux/bckp/zvk/gong.mp3
#zenity --warning --text=backup_gotov

Radila je bez greške do danas. Jednostavno je stala u sred posla. Na kompu se nije radilo, na ekranu je bio screensaver i svirao je audacious. Postoji li načinm da saznam što je bilo?

Još jedno pitanje. Pokušao sam skriptu izvesti ručno u shellu. Odradila je sve bez problema. Međutim u djelu u kom detektiram nedjelju kod pokretanja cronom treba pisati Sun, a kod ručnog Ned. Na kompu mi je ubuntu na hrv. jeziku.

treće, ima li ubuntu ili debian alat za pregledavanje logova kao što ima mandriva?

Re: Omanila skripta

Poslao slobodan on 02.08.2010 11:08:28
Alat za pregledanje logova? Imaš less/more, tail, head, grep, awk, sed, i moš na netu potražit raznorazne log colorizere. Ako misliš na GUI, nemam pojma ni kako to ima mandriva ni što ima kao ekvivalent ubuntu.

Kod ove tvoje greške ja bi prvo pogledao cron logove.

Re: Omanila skripta

Poslao GorkiPelin on 02.08.2010 11:45:26
Ovo da ti naredba date drugačije radi iz shella i iz crona nije niš čudno, jer cron ne koristi isti environment kao i shell. Recimo cron ne sourca /etc/profile i to.

Pokreni je sa engleskim localeom, npr.

LC_ALL="en_US" /staza/do/skripta.sh

A što se tiče ovog prvog pitanja, vidiš li barem na kojoj je naredbi stala skripta? Malo više logiranja bi možda trebao dodati.
Kako vidiš da je stala usred posla? Da li ostane proces visiti?

Re: Omanila skripta

Poslao gigolo on 02.08.2010 15:39:31
Hvala na odgovorima. Nisam ništa pametniji.
Slobodane, cron je uredno pokremuo skriptu ko i svaki dan i na njega nemam zamjerku.
Skripta je stala u djelu koji se izvršava nedjeljom nakon kopiranja direktorija linux. Ko šta vidite skripta samo kopira i ima zvučnu i vizualnu dojavu rada.
Neznam zašto je stala iz čista mira. Gledam logove i ne nalazim ništa pametno. Viditi ću danas u 17 šta će biti.
Našao sam gui za logove: ksystemlog

Re: Omanila skripta

Poslao gigolo on 02.08.2010 18:09:33
Skripta odradila. Međutim jučer je stala u 'nedjeljnom' djelu taklo da ću još pratiti u sljedeću nedjelju.

Re: Omanila skripta

Poslao gigolo on 08.08.2010 17:40:12
Danas je sve ok.

Re: Omanila skripta

Poslao gigolo on 01.10.2010 17:53:03
Opet skripta stala iz čista mira. Pokrenuo sam je zatim ručno i pratio u shellu. Odradila je ko švicarski sat. Oba zastoja su bila na Ubuntu. Treba li se ostaviti Ubuntua i koristiti nešto drugo?
Kod oba zastoja stroj nije bio opterećen. A kako sam dorađivao skriptu opet je pejstam. Svaki konstruktivni komentar je dobro došao.
Skripta:

#!/bin/bash
mpg123 /home/davor/linux/bckp/zvk/zahod.mp3
cp /home/davor/linux/bckp/slk/bckp.gif /home/davor/Desktop
cp /home/davor/linux/bckp/kad.txt /home/davor/linux/bckp/kad-old.txt
echo $(date) > /home/davor/linux/bckp/kad.txt
cd /media/store
echo "Backup"
mpg123 /home/davor/linux/bckp/zvk/apert.mp3
echo "Lekcije"
cp /home/davor/linux/bckp/slk/lkcj.gif /home/davor/Desktop
rm -fr Lekcije
cp /home/davor/Lekcije /media/store -R
rm /home/davor/Desktop/lkcj.gif
mpg123 /home/davor/linux/bckp/zvk/apert.mp3
echo "linux"
cp /home/davor/linux/bckp/slk/lnx.gif /home/davor/Desktop
rm -fr linux
cp /home/davor/linux /media/store -R
rm /home/davor/Desktop/lnx.gif
mpg123 /home/davor/linux/bckp/zvk/apert.mp3
echo "Razno"
cp /home/davor/linux/bckp/slk/rzn.gif /home/davor/Desktop
rm -fr Razno
cp /home/davor/Razno /media/store -R
rm /home/davor/Desktop/rzn.gif
mpg123 /home/davor/linux/bckp/zvk/apert.mp3
echo "Slike"
cp /home/davor/linux/bckp/slk/slk.gif /home/davor/Desktop
rm -fr Slike
cp /home/davor/Slike /media/store -R
rm /home/davor/Desktop/slk.gif
mpg123 /home/davor/linux/bckp/zvk/apert.mp3
echo "Web"
cp /home/davor/linux/bckp/slk/wb.gif /home/davor/Desktop
rm -fr Web
cp /home/davor/Web /media/store -R
rm /home/davor/Desktop/wb.gif
mpg123 /home/davor/linux/bckp/zvk/apert.mp3
echo "Obrada"
cp /home/davor/linux/bckp/slk/obr.gif /home/davor/Desktop
rm -fr Obrada
cp /home/davor/Obrada /media/store -R
rm /home/davor/Desktop/obr.gif
mpg123 /home/davor/linux/bckp/zvk/apert.mp3
echo "Spremi"
cp /home/davor/linux/bckp/slk/spr.gif /home/davor/Desktop
rm -fr Spremi
cp /home/davor/Spremi /media/store -R
rm /home/davor/Desktop/spr.gif
mpg123 /home/davor/linux/bckp/zvk/apert.mp3
echo "Download"
cp /home/davor/linux/bckp/slk/dwn.gif /home/davor/Desktop
rm -fr Download
mkdir Download
cp /home/davor/Download/00000 /media/store/Download -R
#cp /home/davor/Download/Sibenik-rat /media/store/Download -R
#cp /home/davor/Download/Alan_Ford /media/store/Download -R
rm /home/davor/Desktop/dwn.gif
mpg123 /home/davor/linux/bckp/zvk/apert.mp3
echo "Glazba"
cp /home/davor/linux/bckp/slk/glz.gif /home/davor/Desktop
cd /media/home2/Glazba
ls * -d | while read f
do
if [ ! -d /media/store/Glazba/$f ]
then
cp /media/home2/Glazba/$f /media/store/Glazba/ -R
else
cd /media/home2/Glazba/$f
ls > /home/davor/.glh.txt
cd /media/store/Glazba/$f
ls > /home/davor/.gls.txt
cmp /home/davor/.glh.txt /home/davor/.gls.txt > /dev/null
if [ $? -eq 1 ]
then
rm -fr /media/store/Glazba/$f
cp /media/home2/Glazba/$f /media/store/Glazba/ -R
fi
rm /home/davor/.glh.txt /home/davor/.gls.txt
fi
done

rm /home/davor/Desktop/glz.gif
mpg123 /home/davor/linux/bckp/zvk/apert.mp3
echo "Video"
cp /home/davor/linux/bckp/slk/vid.gif /home/davor/Desktop
cd /media/home2/Video
ls * -d | while read f
do
v=`ls -dl $f`
#echo $v
v=$(echo ${v:0:1})
#echo $v
if [ "$v" = "d" ]
then
if [ "$f" != "Porno" ]
then
if [ ! -d /media/store/Video/$f ]
then
cp /media/home2/Video/$f /media/store/Video/ -R
else
cd /media/home2/Video/$f
ls > /home/davor/.glh.txt
cd /media/store/Video/$f
ls > /home/davor/.gls.txt
cmp /home/davor/.glh.txt /home/davor/.gls.txt > /dev/null
if [ $? -eq 1 ]
then
rm -fr /media/store/Video/$f
cp /media/home2/Video/$f /media/store/Video/ -R
fi
cd /media/home2/Video
rm /home/davor/.glh.txt /home/davor/.gls.txt
fi
fi
fi
if [ "$v" = "-" ]
then
if [ ! -f /media/store/Video/$f ]
then
cp /media/home2/Video/$f /media/store/Video/
fi
fi
done

cd /media/home2/Video/Porno
ls * -d | while read f
do
v=`ls -dl $f`
#echo $v
v=$(echo ${v:0:1})
#echo $v
if [ "$v" = "d" ]
then
if [ ! -d /media/store/Video/Porno/$f ]
then
cp /media/home2/Video/Porno/$f /media/store/Video/Porno/ -R
else
cd /media/home2/Video/Porno/$f
ls > /home/davor/.glh.txt
cd /media/store/Video/Porno/$f
ls > /home/davor/.gls.txt
cmp /home/davor/.glh.txt /home/davor/.gls.txt > /dev/null
if [ $? -eq 1 ]
then
rm -fr /media/store/Video/Porno/$f
cp /media/home2/Video/Porno/$f /media/store/Video/Porno/ -R
fi
cd /media/home2/Video/Porno
rm /home/davor/.glh.txt /home/davor/.gls.txt
fi
fi
if [ "$v" = "-" ]
then
if [ ! -f /media/store/Video/Porno/$f ]
then
cp /media/home2/Video/Porno/$f /media/store/Video/Porno/
fi
fi
done
rm /home/davor/Desktop/vid.gif
echo Gotovo
echo $(date) >> /home/davor/linux/bckp/kad.txt
rm /home/davor/Desktop/bckp.gif
mpg123 /home/davor/linux/bckp/zvk/zahod.mp3
#zenity --warning --text=backup_gotov

Re: Omanila skripta

Poslao wrapper on 01.10.2010 22:02:44
Bok!
Mozes pokusati pozvati bash u debug modu i pogledati sto se dogadja.

# Start in debug mode and Send stderr to file
$bash -x script.sh 2> log.txt

Poslije pogledaj \"log.txt\" za greske.


Ako ne zelis cijeli skript provjeravati, mozes provjeriti
samo dio koda.

Debugging part of a script:

set -x # activate debugging
# your commands go here...
set +x # stop debugging


$./script.sh 2> log.txt


Takodjer, mozes pogledati MAN \"set\" za jos opcija.

set -n, provjera sintakse bez izvrsenja
set -t
set -v

Re: Omanila skripta

Poslao nvucinic on 02.10.2010 10:10:00
Citat:



cd /media/home2/Video/Porno
ls * -d | while read f
do
v=`ls -dl $f`
#echo $v
v=$(echo ${v:0:1})
#echo $v
if [ "$v" = "d" ]
then
if [ ! -d /media/store/Video/Porno/$f ]
then
cp /media/home2/Video/Porno/$f /media/store/Video/Porno/ -R
else
cd /media/home2/Video/Porno/$f
ls > /home/davor/.glh.txt
cd /media/store/Video/Porno/$f
ls > /home/davor/.gls.txt
cmp /home/davor/.glh.txt /home/davor/.gls.txt > /dev/null
if [ $? -eq 1 ]
then
rm -fr /media/store/Video/Porno/$f
cp /media/home2/Video/Porno/$f /media/store/Video/Porno/ -R
fi
cd /media/home2/Video/Porno
rm /home/davor/.glh.txt /home/davor/.gls.txt
fi
fi
if [ "$v" = "-" ]
then
if [ ! -f /media/store/Video/Porno/$f ]
then
cp /media/home2/Video/Porno/$f /media/store/Video/Porno/
fi
fi
done




Re: Omanila skripta

Poslao gigolo on 02.10.2010 14:07:14
Wraperu, puno ti hvala za ove upute. Proučiti ću. Linux me stalno iznenađuje i oduševljava svojim mogućnostima. Bar da na ovom forumu ima više postova preko kojih se upoznaje OS. Ja o mogućnostima Linuxa neznam ništa, a volio bih znati.

Vučiniću, sivi tiću, ko je bez grijeha nek prvi baci kamen. Ja iman dojam da ti mene jako voliš. Ajmo ti ija biti dobri prijatelji. Može li?

Ova poruka je od: http://www.linux.hr/newbb/viewtopic.php?forum=4&topic_id=2336