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?

2
  • 2
    you can write in a script what you write at the terminal. Commented Aug 2, 2019 at 8:24
  • do you have an example how to do it ? Commented Aug 2, 2019 at 8:28

1 Answer 1

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)

Sign up to request clarification or add additional context in comments.

5 Comments

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 ?
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 )
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 ""
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 )
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.