Contenu | Rechercher | Menus

Annonce

Si vous avez des soucis pour rester connecté, déconnectez-vous puis reconnectez-vous depuis ce lien en cochant la case
Me connecter automatiquement lors de mes prochaines visites.

À propos de l'équipe du forum.

#1 Le 15/09/2013, à 19:53

malagasy

[Script Shell] Envoyer un fichier avec attachment a l'utilisateur Root

Bonjour,

C'est plus ou moins mon premier script, alors j'aurai souhaité que quelqu'un me corrige ou l'ameliore ce script si nécessaire. Merci d'avance.

Ci-dessous le sujet, désolé si je ne l'ai pas traduit:

1. Write a shell script called /tmp/shellscript.sh
2. Have the shell script gather the current memory configuration and CPU information
3. Write that data to a file called /tmp/memory
4. In the script, write out to the /tmp/users file with current-logged-in users information (you could the w command to gather this information)
5. When running the script, pass a single parameter to it which will determine how many many itterations of top to run. With that information passed to the script, run top in batch mode with the number of iterations passed to it on the command line. For example, when you type shellscript.sh 2, it will run top 2 times. Output the top data to a file called /tmp/top
6. Create a tar file of the /tmp/memory, /tmp/users, and /tmp/top files, and name the file with today's date, as in this format: tarfile-15092013.tgz. The date of the file must be notated as a VARIABLE in the script
7. The last entry in the script should have the tar file emailed to the local root user with the subject line "tarfile attached". Run the script once to generate the file.

#!/bin/sh

VARIABLE=`date +%d%m%Y`

clear
cat /proc/cpuinfo /proc/meminfo > /tmp/memory
w > /tmp/users
top - n $1 -b > /tmp/top
tar -czPf tarfile -$VARIABLE.tgz /tmp/memory /tmp/users /tmp/top

echo "File generated by script" | mutt -s "tarfile attached" -a "tarfile.$VARIABLE.tgz" root

Dernière modification par malagasy (Le 15/09/2013, à 21:45)

Hors ligne