Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
#!/usr/bin/sh OR
#!/usr/bin/ksh OR
#!/usr/bin/csh OR
#!/usr/bin/bash OR
No. De parametros
$0
============Shift Command=======
=================Operators==========================
++
+
!~
*/%
+<< >>
<= >=
<>
== !=
&
^
Bitwise exclusive OR
|
Bitwise OR
&&
Logical AND
||
Logical OR
=======Variaveis====
Global (existe enquanto a sessao estiver aberta)
export nomevar=valor
nomevar=valor
Ex :
export TERM=vt100 (variavel de ambiente)
export DBDATE=Y4MD- (var. De ambiente)
export matricula=20044 (var global)
String
nome=Li
nome1=lliam
conc=$nome$nome1
echo $conc
Inteiro
le cont=1 ou cont=1
let soma=$cont+2
let x'1 + 4' ou let x=1+4
let x=$x+1
utilisar let quando quizer manipular variavel
Array
${var [*]}
${#var[*]}
${#var[n]}
Ambiente
$USER
$PATH
$HOME
$PS1
$SHELL
$TERM
$$
VAR=''VALOR''
POINTER=''VAR''
echo ${!POINTER}
resp : VALOR
resp : a
====comparacao numerica====
A=5 ; b=7
if (($a== $b)) then
echo '' valores iguais''
else
echo ''valores differentes''
fi
if [testes condicionais]
then
commands
fi
=========if..then=============
if [ test_command ]
then
commands
else
commands
fi
====comparacao de strings
a=inteiro ; b=metade
if [[$a = $b]] then
echo ''variaveis iguais''
else
echo '' variaveis diferentes''
fi
===testa se variavel tem conteudo====
=======if..then..elif===============
if [ test_command ]
then
commands
elif [ test_command ]
then
commands
elif [ test_command ]
then
commands
.
.
else (Optional)
commands
fi
verdadeira se...
- d file
Se diretorio
-f file
See file
-r arquivo
-w arquivo
-x arquivo
-a arquivo
Se arquivo existe
-s arquivo
-O arquivo
test -d /usr/local/bin
if [ $? -eq 0 ] # Check the return code
then
echo /usr/local/bin does exist
else
echo /usr/local/bin does NOT exist
fi
or
if test -d /usr/local/bin
then
echo /usr/local/bin does exist
else
echo /usr/local/bin does NOT exist
fi
-G arquivo
test -r nomearq
echo $ ?
var=5
echo $ ?
or
If [ -d /usr/local/bin ]
then
echo /usr/local/bin does exist
else
echo /usr/local/bin does NOT exist
fi
(=0) sucesso
echo $var4
echo $ ?
(=1) sem sucesso
For statement
for loop_variable in argument_list
do
commands
done
While statement
while test_command_is_true
do
commands
done
Until statement
until test_command_is_true
do
commands
done
Case
case $variable in
match_1)
commands_to_execute_for_1
;;
match_2)
commands_to_execute_for_2
;;
match_3)
commands_to_execute_for_3
;;
.
.
.
*)
(Optional - any other value)
commands_to_execute_for_no_match
;;
esac
cd
- Change directory
ls
wildcards
- *matches any number of characters, ? matches a
single character
file
cat
pr
pg or page
more
clear
cp or copy
- Copy a file
chown
chmod
- Change file modes, permissions
777 tudo #e permitido para todos
700 s#o o utilizador tem todas as permiss~oes
000 nada para ningu#em...
755 s#o o utilizador pode adicionar/remover
644 s#o o utilizador pode escrever
600 s#o o utilizador pode ler e escrever
666 todos podem ler e escrever
rm
mv
- Rename a file
mkdir
- Create a directory
rmdir
- Remove a directory
grep
- Pattern matching
egrep
find
date
echo
sleep
seconds
wc
a file
head
tail
diff
sdiff
- Compare two files side by side (requires 132character display)
spell
- Spell checker
enable
cal
- Display a calendar
who
last
write
wall
rwall
rsh or remsh
df
- Filesystems statistics
ps
netstat
vmstat
iostat
uname
- Name of the current operating system, as well as
machine information
sar
basename
man
su
cut
awk
sed
vi
emacs
>>
<<
mail -s 'Backup status' vivek@nixcraft.co.in<<EOF
The backup job finished.
End date: $(date)
Hostname : $(hostname)
Status : $status
END_OF_EMAIL
EOF
>
cd /usr/local/bin
pwd
======silent running=====
$ ls arquivonaoexistente > /dev/null 2> /dev/null
|
|--stderr
|--stdout
or
$ ls arquivonaoexistent > /dev/null 2>&1
||
- Logical ORcommand1 || command2execute
command2 if command1 fails
&
- Execute in background
&&
- Logical ANDcommand1 && command2
execute command2 if command1 succeeds
Kill
ps
ps -f
ps -ef
ps -A
ps -Kf
ps auxw
$Cut
$ cat /etc/passwd | cut -d : -f1 | sort | uniq
typeset -u VARIABLE
VARIABLE=True
echo $VARIABLE
TRUE
typeset -l VARIABLE
VARIABLE=True
echo $VARIABLE
true
wall
rwall
write
talk
===========Cron Tables==========
By default, any user can create a cron table with the crontab -e command
but the Systems Administrator can control which users are allowed to create and edit cron tables with the cron.allow and
cron.deny files. When a user creates his or her own cron table the commands, programs, or scripts will execute in that
users environment. It is the same thing as running the users $HOME/.profile before executing the command.
1 0 1 1 * /usr/bin/banner Happy New Year > /dev/console
| | | | |
| | | | |---weeday (0-6 for sunday to saturday)
| | | |-----month (1 through 12)
| | |-------Day of the month (1 through 31)
| |---------Hour (0 through 23)
|-----------Minute (0 through 29)
5,20,35,50 * * * *
/usr/local/bin/systemcheck.ksh
============at Command===========
executes commands at a specific time
2>&1 >/dev/null
====================