/
Forside
/
Teknologi
/
Operativsystemer
/
Linux
/
Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn
*
Kodeord
*
Husk mig
Brugerservice
Kom godt i gang
Bliv medlem
Seneste indlæg
Find en bruger
Stil et spørgsmål
Skriv et tip
Fortæl en ven
Pointsystemet
Kontakt Kandu.dk
Emnevisning
Kategorier
Alfabetisk
Karriere
Interesser
Teknologi
Reklame
Top 10 brugere
Linux
#
Navn
Point
1
o.v.n.
11177
2
peque
7911
3
dk
4814
4
e.c
2359
5
Uranus
1334
6
emesen
1334
7
stone47
1307
8
linuxrules
1214
9
Octon
1100
10
BjarneD
875
Bash script
Fra :
Trespasser
Dato :
20-03-02 10:49
Hejsa
Jeg sidder og roder med et script men jeg får denne fejl:
date: invalid date `fre mar 01 03:12:12 2002'
expr: syntax error
/glftpd/bin/Spacemaker.sh: [: =: unary operator expected
Hvorfor kommer denne fejl ? Nu skal det lige siges at jeg ikke er nogen
programmerings-haj og det script er et jeg har downloadet fra en hjemmeside
af.
Hvis det er ønskeligt kan jeg godt smide scriptet her.
Mvh
Brian
Peter Makholm (
20-03-2002
)
Kommentar
Fra :
Peter Makholm
Dato :
20-03-02 11:21
"Trespasser" <n97bm001@_SPAM_get2net.dk> writes:
> Jeg sidder og roder med et script men jeg får denne fejl:
> date: invalid date `fre mar 01 03:12:12 2002'
Formodentlig parses uddata fra date(1) et eller andet sted (Af date
selv???)}. Du kan løse det på flere måder.
Den nok letteste er at indsætte 'LANG=C' eller 'LC_TIME=C' et passende
sted i scriptet. Enten bare på en linje for sig i begyndelsen.
Den korrekte måde vil dog nok være at få den date, der genererer en
dato til at genererer den i et genkendeligt format.Enten ved at
tilføje flaget -R eller -I til date-kaldet. Så vil datoen bliv vist på
en locale-uafhængig måde.
> expr: syntax error
> /glftpd/bin/Spacemaker.sh: [: =: unary operator expected
Den kan jeg ikke lige genkeden uden at se scriptet.
> Hvis det er ønskeligt kan jeg godt smide scriptet her.
Hvis det ikke er for langt, vil det måske være en god ide.
--
Emacs er det eneste moderne styresystem der ikke er multitrådet.
Trespasser (
20-03-2002
)
Kommentar
Fra :
Trespasser
Dato :
20-03-02 11:34
Sorry jeg kom lige til at sende det til dig også, Peter
> > Jeg sidder og roder med et script men jeg får denne fejl:
> > date: invalid date `fre mar 01 03:12:12 2002'
> Formodentlig parses uddata fra date(1) et eller andet sted (Af date
> selv???)}. Du kan løse det på flere måder.
> Den nok letteste er at indsætte 'LANG=C' eller 'LC_TIME=C' et passende
> sted i scriptet. Enten bare på en linje for sig i begyndelsen.
Det prøvede jeg; men med samme resuiltat.
> Den korrekte måde vil dog nok være at få den date, der genererer en
> dato til at genererer den i et genkendeligt format.Enten ved at
> tilføje flaget -R eller -I til date-kaldet. Så vil datoen bliv vist på
> en locale-uafhængig måde.
>
> > expr: syntax error
> > /glftpd/bin/Spacemaker.sh: [: =: unary operator expected
> Den kan jeg ikke lige genkeden uden at se scriptet.
> > Hvis det er ønskeligt kan jeg godt smide scriptet her.
> Hvis det ikke er for langt, vil det måske være en god ide.
Her er det. Jeg har dog slette lidt for at det ikke fylder for meget:
#!/bin/bash
# Path to where this file is located.
spacemaker="/glftpd/bin/Spacemaker.sh";
# Path to store temporary files and the .lock file.
tmppath="/tmp";
# Echo moved/deleted dirs to glftpd.log? (0=no 1=yes)
glftpdlog=1;
# Delete nuked dirs instead of moving them? (0=no 1=yes)
deletenukes=1;
# Path to glftpd.log (only needed if you enabled logging above).
log_file="/glftpd/ftp-data/logs/glftpd.log";
# Path to your glftpd.conf.
conf_file="/etc/glftpd.conf";
# Specify the devices to clean space on.
# The buffer is to clean up more space than needed which might prevent the
# script from running so often (which might slow down the site).
# So you can have the script clean up 10GB but it only does this when it
# reaches say below 1GB.
# dev[x]="/dev/hd?:required.free.space.in.MB:buffer.in.MB"
dev[0]="/dev/hdx:500:2500";
dev[1]="/dev/hdy:500:2500";
# Specify the number of listed devices above.
# numdevs=dev[max] + 1
numdevs=2;
# Help paths. Paths to make it easier specifying the other paths.
inpath="/glftpd/site/Incoming";
outpath="/glftpd/site/Archive";
# [ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* ]
# This is the very core of the configuration part.
# This is where you specify what things go where.
# If you make any mistakes here it might go very bad. So be warned.
# I will try to explaing the script here a little:
# The script will first go through the list of devices specified.
# For each device it will then search through the paths. If it finds any
# matching paths it will try to determine which dir in any of the paths is
# the oldest. It does this by checking the dirs modification time.
# If it finds a dir it will try to either move or delete it.
# Before moving the dir it checks to make sure there is space on the
# destination device. If there isn't enough space it will try to make space
# there by running the script with that device as input.
# This is why you also need to specify in what dirs on the destination drive
# the script can clean up. You don't need to list the destination devices in
# the device list for this though. If you do, it will only mean that the
# script will check those devices too and that's not what we want.
# I will illustrate this by making an example.
#dev[0]="/dev/hda:500";
#numdevs=1;
#inpath="/glftpd/site/Incoming";
#outpath="/glftpd/site/Archive";
#path[0]="/dev/hda:Incoming:$inpath/ISO/Apps/:/dev/hdb:Archive:$outpath/ISO/
Apps/:ISO-Apps";
#path[1]="/dev/hdb:Archive:$outpath/ISO/Apps/::::ISO-Apps";
#numpaths=2;
# The example above will make the script move dirs found in
# /site/Incoming/ISO/Apps to /site/Archive/ISO/Apps.
# If there isn't enough space in the Archive it will delete the oldest dir
# found in /site/Archive/ISO/Apps.
# If you don't want something moved to archive simply leave out to
# destination configs on the first path.
# When sending information to the log you might want to know this.
# "Moving <some dir> that is an $dirtype from $indesc to $outdesc." becomes
# "Moving <some dir> that is an ISO-Apps from Incoming to Archive.".
# Feel free to edit the echo syntax below yourself. But make sure you know
# what you are doing.
# [ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* ]
# Specify what dir on what device to move to what dir on what device.
# Specify what dir on what device to delete.
# If you don't want something to be archived ignore outdev, outdescription
# and outpath and it will be deleted.
# Do NOT forget to add Archive paths so the script can delete in Archive
# when it needs space there.
# path[x]="indev:indescription:inpath:outdev:outdescription:outpath:dirtype"
# path[x]="indev:indescription:inpath::::dirtype"
path[0]="/dev/hdx:Incoming:$inpath/Stuff/:/dev/hdy:Archive:$outpath/Stuff/:S
tuff"
path[1]="/dev/hdy:Archive:$outpath/Stuff/::::Stuff"
# Number of paths listed above.
# numpaths=path[max] + 1
numpaths=2;
# Echo syntax. Be very careful when editing these!
# Deleting from an incoming path with success.
incomingdeletesuccess="echo \`date \"+%a %b %e %T %Y\"\` INFO:
\\\"SpaceMaker\\\" \\\"\$oldindesc free: \$freespace MB - Required:
\$reqspace MB - Freed \$oldsize MB by deleting \$oldestrel
\(\$oldesttype\)\\\""
# Delete from an archive path with failure.
archivedeletefail="echo \`date \"+%a %b %e %T %Y\"\` INFO:
\\\"SpaceMaker\\\" \\\"Free: \$olddevspace MB - Required: \$oldsize MB - No
dirs found to delete. Contact SiteOP ASAP\\\""
# Delete from an archive path with success.
archivedletesuccess="echo \`date \"+%a %b %e %T %Y\"\` INFO:
\\\"SpaceMaker\\\" \\\"\$oldindesc free: \$freespace MB - Required:
\$reqspace MB - Freed \$oldsize MB by moving \$oldestrel \(\$oldesttype\) to
\$oldoutdesc\\\""
# Error when neither delete or move was triggered.
errorondeleteormove="echo \`date \"+%a %b %e %T %Y\"\` INFO:
\\\"SpaceMaker\\\" \\\"Script malfunctioning. Contact SiteOP ASAP\\\""
# Error when no dirs are found to move or delete.
nodirsfound="echo \`date \"+%a %b %e %T %Y\"\` INFO: \\\"SpaceMaker\\\"
\\\"\$oldindesc free: \$freespace MB - Required: \$reqspace MB - No dirs
found to delete/move. Contact SiteOP ASAP\\\""
# Caught in an endless loop.
endlessloop="echo \`date \"+%a %b %e %T %Y\"\` INFO: \\\"SpaceMaker\\\"
\\\"I seem to have been caught in an endless loop. Contact SiteOP ASAP\\\""
# How does your nuked dirs look?
nukesyntax=`grep nukedir_style $conf_file | grep -v '#' | cut -f2-2 | awk -F
'%' -F '-' '{print $1}'`;
# [ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* ]
# [ * CONFIGURATION DONE
* ]
# [ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* ]
makespace () {
j=0; foundnuke=0; todo="";
oldest=`date -d NOW +%s`; oldestrel=""; oldindesc=$devname;
ctime=`date -d '2 minutes' +%s`;
while [ $j -lt $numpaths ] ; do
indev=`echo ${path[$j]} | awk -F : '{ print $1 }'`;
if [ "$devname" = "$indev" ]; then
indesc=`echo ${path[$j]} | awk -F : '{ print $2 }'`;
indir=`echo ${path[$j]} | awk -F : '{ print $3 }'`;
destdev=`echo ${path[$j]} | awk -F : '{ print $4 }'`;
destdesc=`echo ${path[$j]} | awk -F : '{ print $5 }'`;
outdir=`echo ${path[$j]} | awk -F : '{ print $6 }'`;
type=`echo ${path[$j]} | awk -F : '{ print $7 }'`;
nukedatum=`ls $indir -l --full-time -t | grep -w "$nukesyntax" |
tail -n1 | tr -s " " | cut -d " " -f6-10`;
datum=`ls $indir -l --full-time -t | tail -n1 | tr -s " " | cut -d
" " -f6-10`;
if [ ! -z "$nukedatum" ]; then
if [ "$foundnuke" == "0" ] ; then
oldest=`date -d NOW +%s`;
fi
foundnuke=1;
ctime=`date -d "$nukedatum" +%s`;
dir=`ls $indir -l --full-time -t | grep -w "$nukesyntax" |
tail -n1 | tr -s " " | cut -d " " -f11-11`;
else
if [ ! -z "$datum" ] && [ "$foundnuke" == "0" ] ; then
ctime=`date -d "$datum" +%s`;
dir=`ls $indir -l --full-time -t | tail -n1 | tr -s " " |
cut -d " " -f11-11`;
else
ctime=`date -d '2 minutes' +%s`;
dir="";
fi
fi
if [ -z $destdev ] || [ -z $outdir ] ; then
todo=delete;
else
if [ $foundnuke = "1" ] && [ $deletenukes = "1" ] ; then
todo=delete;
else
todo=move;
fi
fi
fi
if [ ! -z $indesc ] ; then
oldindesc=$indesc;
fi
if [ `expr $ctime "<=" $oldest` = 1 ] ; then
oldest=$ctime;
oldestrel="$dir";
oldesttype="$type";
oldin="$indir";
oldindesc="$indesc";
olddev="$destdev";
oldout="$outdir";
oldoutdesc="$destdesc";
oldtodo="$todo";
oldsize=`du -s -m $oldin$oldestrel | cut -f1`;
fi
j=`expr $j + 1`;
done
loop=`expr $loop + 1`
if [ ! -z "$oldestrel" ]; then
if [ $oldtodo = "delete" ] ; then
rm -rf $oldin$oldestrel
if [ $glftpdlog = "1" ] ; then
eval $incomingdeletesuccess >> $log_file
# echo `date "+%a %b %e %T %Y"` INFO: \"SpaceMaker\" \"$oldindesc
free: $freespace MB - Required: $reqspace MB - Freed $oldsize MB by deleting
$oldestrel \($oldesttype\)\" >> $log_file
fi
else
if [ $oldtodo = "move" ] ; then
olddevspace=`df -m | grep $olddev | awk '{print $4}'`;
olddevspace=`expr $olddevspace`;
while [ $olddevspace -lt $oldsize ] && [ $errorlevel = "0" ] ;
do
$spacemaker $olddev $olddevspace $oldsize
errorlevel=`echo $?`;
olddevspace=`df -m | grep $olddev | awk '{print $4}'`;
olddevspace=`expr $olddevspace`;
done
if [ $olddevspace -lt $oldsize ] ; then
if [ $glftpdlog = "1" ] ; then
eval $archivedeletefail >> $log_file
# echo `date "+%a %b %e %T %Y"` INFO: \"SpaceMaker\"
\"Free: $olddevspace MB - Required: $oldsize MB - No dirs found to delete.
Contact SiteOP ASAP\" >> $log_file
fi
errorlevel=1;
exit $errorlevel
else
mv -f $oldin$oldestrel $oldout
chown root.root -R $oldout$oldestrel
chmod 755 -R $oldout$oldestrel
touch $oldout$oldestrel
if [ $glftpdlog = "1" ] ; then
eval $archivedletesuccess >> $log_file
# echo `date "+%a %b %e %T %Y"` INFO: \"SpaceMaker\"
\"$oldindesc free: $freespace MB - Required: $reqspace MB - Freed $oldsize
MB by moving $oldestrel \($oldesttype\) to $oldoutdesc\" >> $log_file
fi
fi
else
if [ $glftpdlog = "1" ] ; then
eval $errorondeleteormove >> $log_file
# echo `date "+%a %b %e %T %Y"` INFO: \"SpaceMaker\" \"Script
malfunctioning. Contact SiteOP ASAP\" >> $log_file
fi
errorlevel=1;
exit $errorlevel;
fi
fi
else
if [ $glftpdlog = "1" ] ; then
eval $nodirsfound >> $log_file
# echo `date "+%a %b %e %T %Y"` INFO: \"SpaceMaker\" \"$oldindesc
free: $freespace MB - Required: $reqspace MB - No dirs found to delete/move.
Contact SiteOP ASAP\" >> $log_file
fi
errorlevel=1;
exit $errorlevel;
fi
if [ $loop = "10" ] ; then
if [ $glftpdlog = "1" ] ; then
eval $endlessloop >> $log_file
# echo `date "+%a %b %e %T %Y"` INFO: \"SpaceMaker\" \"I seem to
have been caught in an endless loop. Contact SiteOP ASAP\" >> $log_file
fi
errorlevel=1;
exit $errorlevel;
fi
}
if [ ! -z $1 ] ; then
if [ -z $2 ] || [ -z $3 ] ; then
echo "Not enough parameters given."
exit 1
fi
devname=$1;
freespace=`expr $2`;
reqspace=`expr $3`;
loop=0; errorlevel=0;
while [ $freespace -lt $reqspace ] && [ $errorlevel = "0" ] ; do
makespace $devname $freespace $reqspace
freespace=`df -m | grep $devname | awk '{print $4}'`;
freespace=`expr $freespace`;
done
else
# Check if the script is running or not (look for .lock file).
# If it is not running we create the .lock file.
if [ -e $tmppath/Spacemaker.lock ] ; then
echo "Script is already running. Remove $tmppath/Spacemaker.lock if
not."
exit 1
else
touch $tmppath/Spacemaker.lock
fi
i=0;
while [ $i -lt $numdevs ] ; do
devname=`echo ${dev[$i]} | awk -F : '{ print $1 }'`;
reqspace=`echo ${dev[$i]} | awk -F : '{ print $2 }'`;
buffer=`echo ${dev[$i]} | awk -F : '{ print $3 }'`;
reqspace=`expr $reqspace`;
buffer=`expr $buffer`;
reqbufspace=`expr $reqspace + $buffer`;
freespace=`df -m | grep $devname | awk '{print $4}'`;
freespace=`expr $freespace`;
loop=0; errorlevel=0;
while [ $freespace -lt $reqspace ] && [ $errorlevel = "0" ] ; do
reqspace=`expr $reqbufspace`;
$spacemaker $devname $freespace $reqspace
errorlevel=`echo $?`;
freespace=`df -m | grep $devname | awk '{print $4}'`;
freespace=`expr $freespace`;
done
i=`expr $i + 1`;
done
rm -f $tmppath/Spacemaker.lock
fi
Søg
Alle emner
Teknologi
Operativsystemer
Linux
Indstillinger
Spørgsmål
Tips
Usenet
Reklame
Statistik
Spørgsmål :
177551
Tips :
31968
Nyheder :
719565
Indlæg :
6408825
Brugere :
218887
Månedens bedste
Årets bedste
Sidste års bedste
Copyright © 2000-2024 kandu.dk. Alle rettigheder forbeholdes.