Bash Script - Check If Three Commands Are True

I am trying to check if all three mountpoint commands return true. However when I run the bash script I get a binary operator expected error.

if [[ mountpoint -q /mnt/foo1 && mountpoint -q /mnt/foo2 && mountpoint -q /mnt/foo3 ]]
then
echo "all three true"
else
echo "all three not true"
fi


Similar Content



How To Avoid Newlines Output In Bash Script

I am have a bash script like this:

#!/bin/bash
while true;
do
(printf %s "$(date '+%A %W %Y %X')"; echo -n ", " ; printf %s "$(ps -eo pcpu,pmem,comm | grep statsd)") >> tope.txt;
sleep 2;
done

What I want is the output of this command be entered into tope.txt like this:

Friday 20 2015 11:28:21, 0.0 0.4 /usr/libexec/systemstatsd

but what I get is output like this in multiline. :

Friday 20 2015 11:28:21
,
0.0 0.4 /usr/libexec/systemstatsd

What can I do to fix this?

Trap Error And Assign In Bash Script

hi
I try to assign return from a _error_handler_function to a variable
this is just a test( dummy test ) not a really case


#!/bin/bash
logfile="/dev/shm/log.err"
exec 2>$logfile
_err_handler(){
v=$(cat $logfile|grep dummy|wc -l);
rm $logfile
echo $v
}

trap _err_handler ERR

x=$(dummy);
echo "x value is $x "
z=$(notrap)
echo "z value is $z"


expected output :
bash-4.1$ sh test2.sh
x value is 1
z value is 0


what is wrong here and how should I fix?

thanks in advance

Check If Files Exists

Hi

this is true:

#!/bin/bash

if [ -a /tmp/jboss7_pid.txt ]; then
echo "it exist!"


but what if I also need to check 2 files in /tmp? lets say jboss4_pid.txt. I tried this but didnt worked out

if [ -a /tmp/jboss7_pid.txt -a /tmp/jboss4_pid.tx ]; then
echo "it exist!"

Value Comparison In Bash Shell Script

I need to compare a value with different fixed value. Below is the code concept I implemented in my bash script but its giving me error.
Here "a' is the nameserver value that I extract using command line from /etc/resolv.conf. I did not put command here.

#! /bin/bash
a=1.2.3.4

if [ $a == 1.2.3.4 || 5.6.7.8 || 8.9.1.4]
then
echo " You have correct ntpserver"
else
echo"wrong ntpserver"

fi

Am I comparing the value correctly or any suggestion?

Thank you

Bash More Commands In One Function

hello

first year of learning linux and bash script
Now i wrote a bash script with a function.
Today i recieved a email from my teacher that 1 function only can have 1 command and no more then 1?

thats a part of the script

Code:
function tx_unreachable_msg()
{
LOGLINE="[$DATE] no ip service unreachable"
typewriter "$NOIPSERVICE niet bereikbaar" .1
sleep 1 
typewriter "Mail wordt verzonden naar $email" .1
mail -s "NO ip mail error" "$email"<<EOF
dynupdate.no-ip.com niet bereikbaar @ $DATE
EOF
}

it's part dutch part english but the point is that the first LOGLINE is forbidden in the function because i use the functie to send a mail end not to write a logline but that's a part of the command in my case?

So what does this function?
If the no ip service is unreachable then it's write to /etc/var/log/no-ip and after the sleep it's send a simpel mail to the adres in the variabele mail.

i read here at the first line:
Quote:
Shell functions are a way to group commands for later execution using a single name for the group.
so is it true that my function is wrong and so no can someone point me to a website where it's say that more commands are allow in 1 function0

grts b

Check Status

I am writing a script to check whether a "sysinfo" is installed in a system or not. sysinfo is a tool that gives information about the system. Its is installed in /usr/local/bin. so at CLI when I type sysinfo, it will display output.

#!/bin/bash
sysinfo=`/usr/local/bin/sysinfo`
echo "$sysinfo"
if [ "$?" = 0 ];then
echo "sysinfo installed"
else
echo "Please install sysinfo"
fi

Concept is, I run the command if it is present, it will show output and exit status of command is 0 else it is not installed. But it is not working as expected. Any thoughts , idea, suggestion.

Bash Scrip Running On Remote Server

This is my script and the syntax to run this script is give ip and next will be the file or script you want to perform on remote server



#!/bin/bash

# The private key used to identify this machine
IDENTITY_KEY=/home/adnew.pem

syntax()
{
echo "Syntax: Ec2.sh server_ip scriptFile]"
echo "For example: ./Ec2.sh server_ip scriptFile"
exit 1
}

if [ $# -ne 2 ]
then
echo not enough arguments
syntax
fi


echo "Running script $2 on $1"
ssh -ttq -i $IDENTITY_KEY ec2-user@$1 sudo -i 'bash -s' < $2
exit
exit
echo "Done"



on script file i have give for testing

touch /root/test
ls /root/test
exit
exit

it makes the file but do not show the ls output by giving error


tcgetattr: Inappropriate ioctl for device

exit


what I have to do ??

Best Way To Run Two Interdependent Scripts

Hi All,

I have two scripts, the aim of these two scripts is, to check whether a particular script is running or not, if it wont runs, then throw a mail.

How i Achieved this output is, I wrote first script.

I created an infinite while loop which performs below steps

1. It creates a touch file
2. Triggers the script which needs to be monitored if its working or not.
3. Removes the touch file.

If the second step fails, then the remove file command will not happen and the script will stuck there itself.

I created an another script which checks the creation time of the touch file and if it is more than ten minutes, it means the second step in the first script is hanged, which also means that particular script is not working.

So if the creation time is more than 2 minutes the second script will throw a mail.

Below are the two scripts.

Code:
#!/bin/ksh



userid="chansd"

filename="/apps/log/check.txt"

while true ;do
touch $filename
pass=`/apps/eDMZ/call_st.ksh $userid`
sleep 20
rm $filename
done

Below script checks the file creation time and throws email if it is older than 2 minutes
Code:
#!/bin/ksh


filename="/apps/log/check.txt"

if [ -f "${filename}" ]
then
if test "`find $filename -mmin +2`"
then
echo "script is not working ! Please act on it" | mail -s "Script  is not working" Example@mail.com
fi


else

        exit 1

fi


What im going to do is

1. I am going to run the first script in background so it runs forever.
2. I am going to run the second script in cron forevry 5 mins to check the file creation time.

3. So if the first script hangs . I will kill the process using process id and after the issue resolves with the inner script, I will run the main script again.

I am new to Linux, Please let me know if this approach will work as expected.

Bash Script For Xfce4 Powermanager Settings Switching Forth And Backward

i need a bash script to switch to zero second on ac the waiting time for turning off the monitor (highlighten in red). same as for on battery (highlighten in purple)

Code:
<?xml version="1.0" encoding="UTF-8"?>

<channel name="xfce4-power-manager" version="1.0">
  <property name="xfce4-power-manager" type="empty">
    <property name="power-button-action" type="empty"/>
    <property name="show-tray-icon" type="empty"/>
    <property name="logind-handle-lid-switch" type="bool" value="true"/> 
    <property name="dpms-on-ac-sleep" type="uint" value="1"/>
    <property name="dpms-on-ac-off" type="uint" value="2"/> 
    <property name="brightness-on-battery" type="uint" value="9"/> 
    <property name="dpms-on-battery-sleep" type="uint" value="1"/>
    <property name="dpms-on-battery-off" type="uint" value="2"/> 
    <property name="lock-screen-suspend-hibernate" type="bool" value="false"/>
    <property name="dpms-enabled" type="bool" value="true"/>
  </property>
</channel>

Check Empty Variable Without Comments

Hello,

They gave me this:
Code:
#!/bin/bash

# Write error message on stderr and die
function die() {
  echo "$@" >&2
  exit 1
}

# Load var from properties files
function load() {
  for propertie in "$@" ; do
    [[ -f "${propertie}" ]] || die "load() : \"${propertie}\" don't exist !"
    while read ; do
echo "${REPLY%=*}"
echo "${REPLY#*=}"
      [[ -n "${REPLY%%=*}" && -z "${REPLY#*=}" ]] || die "load() : Variable \"${REPLY%%=*}\" is empty!"
      eval "${REPLY%%=*}"=\'"${REPLY#*=}"\'
    done < "${propertie}"
  done
}

load "manage_srcds.conf"
echo "SRCDS_TICKRATE=$SRCDS_TICKRATE"
echo "SRCDS_SCREEN=$SRCDS_SCREEN"
echo "SRCDS_SRCDS_GAME_NAME=$SRCDS_GAME_NAME"
echo "SRCDS_MAXPLAYERS=$SRCDS_MAXPLAYERS"

but, return:
Quote:
###################################################
###################################################
load() : Variable "###################################################" is empty!

cat manage_srcds.conf

I just wish that there was no empty variable excluding those who do not have integer.

Best regards,