Advertisement
adriweb

shell exam

Dec 12th, 2013
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.37 KB | None | 0 0
  1. # 1)
  2. mv toto.txt ~/titi.txt
  3.  
  4.  
  5. # A partir de la , on considere que l'on est dans le home.
  6. # Sinon, il suffit de faire un cd
  7.  
  8. # 2)
  9. theDate=`date +%Y%m%d`
  10. tar -cf testn4_${theDate}_DELIVERY.tar .
  11.  
  12. # 3)
  13. find . -name "*.java" -o -name "*.c"
  14.  
  15. # 4) avec boucle :
  16. for javaFile in *.java; do
  17.     chmod 640 $javaFile
  18. done
  19. #sans boucle :  chmod 640 *.java
  20.  
  21. # 5)  Dans ce cas précis, pas besoin d'autre vérification du "mot" printf...
  22. sed -E -i.bak 's/^(.*)?printf\(/fprintf\(/g' bonjour.c
  23.  
  24. # 6)
  25. for i in {1..5}; do
  26.     echo "|Bertrand$i|Adrien$i|014213370$i|" >> input.txt
  27. done
  28. awk 'BEGIN { FS = "|" } ; {print $2 "_" $3;}' input.txt
  29.  
  30. # 7)
  31. for f in `find -iname "*.bak"`; do
  32.     new=`echo $f | sed -E 's/bak$/c/g'`
  33.     mv $f $new
  34. done
  35.  
  36. # 8) # Si on considere qu'une device est tout ce qui est monté ....
  37. mount
  38. # sinon, ceci marche pour les /dev/*   :   df | grep "^\/dev"
  39.  
  40. # 9)
  41. awk 'BEGIN { FS = ":" } ; {print $2,$3,$4;}' text.txt
  42.  
  43. # 10) Bonus
  44. kill `ps | grep " toto$" | awk '{print $1}' | xargs echo`
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58. # exo 2 :
  59.  
  60.  
  61.  
  62. #!/bin/bash
  63.  
  64. while true; do
  65.     for i in {5..0}; do
  66.         echo $i
  67.         sleep 1
  68.     done
  69.     tmp=`jobs -l | grep "JadoreLesScriptsShell" | grep Running | wc -l`
  70.     if [ "x-$tmp" != "x-1" ]
  71.         ./JadoreLesScriptsShell    
  72.         jobs -l | grep "JadoreLesScriptsShell" | grep Running | awk '{print $2}' > JadoreLesScriptsShell.pid
  73.     fi
  74. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement