If Statement Fails When It Shouldn't

For some reason this statement reports "FALSE" when in fact it shouldn't. Any idea why?

Code:
#!/bin/bash

var1=$(nc -dvzw5 thebes.openshells.net 22)
var2='Connection to thebes.openshells.net 22 port [tcp/ssh] succeeded!'
if [ "$var1" = "$var2" ]; then
echo TRUE
else
echo FALSE
fi



Similar Content



Help With 'CASE'

Hi guys,

i'm beginner with Unix, I tried my best, but I Really don't know how to finish it .

here's my problem : I have to do something like Student system - student's name | subjects | mark |credits.

after starting script it will ask you for Student's name, then which subject, then the mark will appear.

It's a homework, and I have my own idea how to solve it, but cannot finish it, i don't want complete solution, just a help!

Code:
#!/bin/bash
echo "Students name"
echo -n "Enter student's name: "
read name
echo
case $name in
Example1|Math) echo "C" ;;
Example2|Programming) echo "D" ;;
Example3|WWW) echo "A" ;;
Example4|Economie) echo "-" ;;
esac

I don't now how to bring together case with second things which is "enter subject".

I appreciate any help

Basic Bash Script

Code:
PREFIX=192.168.1
OCTET=1
while [ $OCTET -lt "255" ]; do
    echo -en "Pinging ${PREFIX}.${OCTET}..."
    ping -c1 -w1 ${PREFIX}.${OCTET} > /dev/null 2>&1
    if [ "$?" -eq "0" ]; then
       echo "OK"
    else
       echo "Failed"
    fi
    let OCTET=$OCTET+1
done

My question is, in the penultimate line, why is it OCTET, and not $OCTET, with a dollar before it, meaning, the variable?

What if it were written:
Code:
let $OCTET=$OCTET+1

Like in C++ (I think) or Python or whatever?

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,

Parameter $1 Isn't Returned After A Case (bash Scripting)

Hello everyone,

I recently started using "function" and "case" in linux but I came across a slight problem

My code:

Code:
function Return
{
echo $1
}

case "$1" in 
 ""       ) echo "give parameters please";;
 [0-9]*   ) echo "No numbers please";;
 *        ) Return;;



So whenever the first parameter is a simple word I would like it returned, but it seems like there is no returned string (empty space)

Also I know I can just write "echo $1" instead of Return, but I'd like to use a function for this.

Can anyone tell me why the function doesn't return $1? Thanks!

Why Wont My Code Work, " SyntaX Error: Unexpected End Of File"

i have been trying to get this peice of code to work but i cant seem to get it to work.
im just starting out coding and kinda poking around in the dark to get this resolved, any help would be much appriciated, thankyou


Quote:
#!/bin/bash

echo "Would you like to scan using nmap or hping?"

read scanner

if "$scanner" = "nmap" : then

echo "Enter the starting IP address :"

read FirstIP

echo "Enter the last IP address :"

read LastIP

echo "Enter the port number you want to scan for :"

read port

nmap -sT $FirstIP-$LastIP -p $port -oG web
cat web | grep open > web1
cat web1 | cut -f2 -d ":" | cut -f1 -d "(" > web2
cat web2


elit



echo "Which IP address would you like to scan?"

read IPaddress

echo echo "What port would you like to scan for ?"

read hpingport

echo "How many packets would you like to send?"

read packets

hping3 -c $packets $IPaddress -p $hpingport > hpingscan

cat hpingscan
thankyou for any help

If Statement For Non Alphanumeric Character

Afternoon forumer's

Im trying to have a if statement perform a check to throw out a string that contains alphanumeric

so anything like ^*&(*"

ive been racking my brain with if statements and checks like

if [ $string = "\^|\*" ]
then
echo "string contains incorrect characters"
fi

however i cant figure it :\

Misbehaving 'echo' Command On Cygwin

Hi,

I've used unix before, but have just started to play with CYGWIN (1.1.3) on windows XP (32 bit). I'm having trouble getting 'echo' to behave as I would expect.

I've created a script called runstuff which contains these lines....
Code:
#!/bin/bash
# This line works as expected....
echo "the user is <$USER> and the hostname is <$HOSTNAME>"
MYVAR1=bill
MYVAR2=fred
# This lines doesn't.....
echo "my first variable is<$MYVAR1> and my second is <$MYVAR2>"

The output I get is this...
Quote:
$ runstuff
the user is <Mike> and the hostname is <MikesLaptop>
> and my second is <fredl

In the first echo statement it is just echoing a couple of external variables - this works as expected. In the 2nd echo example the two variables are internal, but the displayed output isn't what I'd expect, my guess is that the first part of the output "my first variable is <bill" has somehow been overwritten by the remainder of the string. Or am I missing something?

I have tried exporting the variables, and I've experimented with wrapping them in quotes, but the results are always the same.

Any help gratefully received.

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>

Simple Ping Bash Script

Hello, I am trying to implement this script, but for some reason, it limits to pinging 192.1681.1 and then 192.168.1.2 infinitely.
Any idea what is wrong with it? Thanks!

Quote:
PREFIX=192.168.1
OCTET=1
while [ "$OCTET" -lt "255" ]; do
echo -en "Pinging ${PREFIX}.${OCTET}..."
ping -c1 -w1 ${PREFIX}.${OCTET}
if [ "$?" -eq "0" ]; then
echo "OK"
else
echo "Failed"
let OCTET=$OCTET+1
fi
done

Better Way Of Writing This Command Of Leaving Multiple Blank Lines

Hi All..

I need to give four lines of gap(Freespace) between two command outputs.

what i did was below

Code:
echo "" >>$LOG_DIR/$LOG_NAME
echo "" >>$LOG_DIR/$LOG_NAME
echo "" >>$LOG_DIR/$LOG_NAME
echo "" >>$LOG_DIR/$LOG_NAME
print "***************** LEVEL 2: Truncating  Tables: Success:  tables Truncated ***********************" >> $LOG/$LOG_NAME
echo "" >>$LOG_DIR/$LOG_NAME
echo "" >>$LOG_DIR/$LOG_NAME
echo "" >>$LOG_DIR/$LOG_NAME
echo "" >>$LOG_DIR/$LOG_NAME
# Run the load scripts.
echo "***************** LEVEL 3: Loading Dupe Check Tables: Success: Dupe Check tables Loaded***********************" >> $LOG/$LOG_NAME


Is there any better way of writing this command to leave multiple lines between two commands.

Please advise...