0

I have some checks that I do every 2 hours to monitor the status of servers like iostat -ch, df -h /DATA, free -mh, ps -aux | grep kafka and other commands and some shell scripts.

How can I group them in one or two scripts to execute them automatically without doing the same check manually every time?

paradx
  • 62
  • 12

1 Answers1

1

So if I understand correctly you want to execute a bunch of commands as one script executed it automatically every two hours?

Start by writing a shell script:

#!/bin/sh

iostat -ch
df -h /DATA
free -mh
ps -aux | grep kafka

and then add it as a cron job (see cron)

paradx
  • 62
  • 12
  • yes I want it to be like that in one file , and by the way I have some shell scripts to verify Firewall and Apps status , can I Put them also in one script ? – AbdelAziz ESSAADI Aug 02 '19 at 09:43
  • I don't see why not, calling scripts from other scripts is a pretty common thing to do. It will run through the script one command after another and when you call another script will call that until it is finished. If you want them to run parallel you can add a `&` after the command to put it in background. Since it seems that you're new to the shell scripting world I suggest to read some tutorial about shell scripts online (e.g [this is one I found after a quick search](https://www.shellscript.sh/index.html) ) – paradx Aug 03 '19 at 13:10
  • I did this `#!/bin/bash # -CPU: echo -e "\e[31;43m***** CPU INFORMATION *****\e[0m" iostat -ch echo "" # -File system disk space usage: echo -e "\e[31;43m***** FILE SYSTEM DISK SPACE USAGE *****\e[0m" df -h /DATA echo "" # -Free and used memory in the system: echo -e "\e[31;43m ***** FREE AND USED MEMORY *****\e[0m" free -mh echo "" # -Kafka Process Status: echo -e "\e[31;43m***** Kafka Process Status *****\e[0m" ps -aux | grep kafka echo "" # -Spark PROCESSES Status: echo -e "\e[31;43m***** Spark Processes Status *****\e[0m" ps -aux | grep kafka echo "" ` – AbdelAziz ESSAADI Aug 06 '19 at 15:27
  • If I where the shell interpreter and got this, I wouldn't want to recognize any command either... Please read up on the topic, I can't fix the script in the comment section especially when you don't provide proper formatting nor error messages btw. why are you using bash? you're not using any special commands `sh` can't do and every *nix operating system has sh not all have bash (see [here](https://stackoverflow.com/questions/5725296/difference-between-sh-and-bash) ) – paradx Aug 07 '19 at 07:09
  • I took the time to unscramble the commands, under debian it runs (either `sh` or `bash` ) so I guess you don't have bash installed and should change the first row to `#!/bin/sh`. Try manually call the script with `sh ./scriptname.sh` – paradx Aug 07 '19 at 07:18