Register
It is currently Mon Sep 01, 2014 7:41 am

need help to fix my script :(


All times are UTC - 6 hours


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Mon Dec 09, 2013 4:23 am   

Joined: Mon Dec 09, 2013 4:20 am
Posts: 2
Can someone help to fix a script with this error in performing the services!

tks


#!/bin/bash
#if [`whoami` == root]; then
sair=1
function sair (){
echo "Deseja realmente sair:"
echo "Digite S, SIM, Sim, sim, Y, Yes, tes para sair, Digite N, não, Não, No no para contnuar!"
read confirma

case "$confirma" in
S | SIM | Sim | Y | YES | yes)
sair=5
;;
N | NAO | Nao | N | NO | no)
echo "Opcao invalida!"
;;
*)
echo "Opcao invalida!"
esac
}

function cadastra (){
echo " Digite o nome a ser cadastrado!"
read nome

if ["` cat /home/aluno/cadastro.txt | cut -d ';' -f 1 | grep -o $nome`" = "" ]; then
echo "Digite o email"
read email
echo "Digite o diteorio que deseja ser monitorado"
read dir

if [ !-d "$dir" ]; then
echo "digite um diretorio valido"
else
echo $nome`;`$email`;`$dir >> cadastro.txt
echo "Cadastrado com sucesso"
fi

else
echo "Usuario ja cadastrado no sistema"

fi
}

function consulta (){
echo "deseja consultar por nome ou email?"
read consulta
if [ $consulta == "nome" ]; then
echo "Digite o nome que deseja consultar"
read nome
resultado=`cat /home/aluno/cadastro.txt | cut -d ';' -f 1 | grep -o $nome`
echo "Usuario cadastrado!"
echo $resultado
elif [ $consulta == "email" ]; then
echo "digite o e-mail que deseja consultar"
read email
resultado=`cat /home/aluno/cadastro.txt | cut -d ';' -f 2 | grep -o $email`
echo "email cadastrado"
echo "$resultado"
fi
}

if [ `whoami` != "root" ]; then
hora=`date +%H`
if [ $hora -lt 12 ]; then
echo "Bojuor"
if [ $hora -lt 18 ]; then
echo "Tardê"
else
echo "buenas noches"
fi
fi

while [ $sair -ne 5 ]; do
echo "Escolha uma Opção:"
echo "1. Cadastro de usuário"
echo "2. Consultar usuário"
echo "3. Realizar Backup"
echo "4. Relatorio"
echo "5. Sair"

read opcao

case "$opcao" in
1)
cadastra
;;
2)
consulta
;;
3)
exporta
;;
4)
bkp
;;
5)
sair
;;
[7-9] | [10-12])
echo "opção não implmentada"
;;
*)
echo "Opção invalida"
;;
esac

done

fi


Top
 Profile  
 PostPosted: Mon Dec 09, 2013 9:51 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 535
hi,

please insert your code between [Code] tag

what error ?

line #25: a space is missing after first square bracket.


Top
 Profile  
 PostPosted: Mon Dec 09, 2013 3:48 pm   

Joined: Mon Dec 09, 2013 4:20 am
Posts: 2
this ok
this running
the problem in this logic!

When you make the registration in level 1.
not registers
appears registration effected successfully message! nevertheless

in item 2 he consults and informs you of the name ....
but in item 1 was not registered anything!

item 5 out ... does not exit the software


Top
 Profile  
 PostPosted: Tue Dec 10, 2013 7:29 pm   
User avatar

Joined: Wed Jun 08, 2011 8:27 am
Posts: 189
Location: outer Shpongolia
Are you hiding the error reports or did you fix the syntax errors meantime?

----

[(0)'s syntax is:
Code:
[ arg1 arg2 ... argN ]

Blanks are needed.

All arguments must be words. « !-d « is wrong for instance.
« ! » should be an argument, as should « -d ».

[ is a command that excepts to see arguments ended by a not optional ] to delimit its end. (Symmetry involved.)

== as a special [(0)'s operator isn't defined by POSIX standards; = is.

----

In your current cases, you want to check whether the variable holding the user's input is empty
before supplying it to grep(1), otherwise it will report that there is no pattern to search for.

Though, the following is a better way to do the same thing:
Code:
if cut -d';' -f1 /path/to/file | grep -Fxq "$var"; then

Also, you should double-quote every variable expansion when in doubt.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP