Can I use hexdump in a shell script? - linux

Can I use hexdump in a shell script?
When I use it I keep getting an error .
syntax error near unexpected token 'hexdump'
#!/bin/bash
#bash-hexdump
# Quick script to check delay of the shotpoints
echo " please enter the complete line name as mentioned in the RAID2 "
read $line
cd /argus/raid2/"$line"
echo
echo " Entering the directory "
echo
for file in /argus/raid2/"$line"/*.ffid
hexdump -e "16 \"%_p\" \"\\n\"" $FFID | sed -n '68,73p' > list1
done
for filename in 'cat list1'
do
sed -n 6p | awk '{print $1}' = $wd
cat list.txt | sed -n 1p | cut -c13-14 = $hh
cat list.txt | sed -n 1p | cut -c15-16 = $mm
cat list.txt | sed -n 2p | cut -c1-2 = $ss
done
while [ true ]
do
$FFID=`ls -1rt $1 | grep -i ffid | tail -1`
echo " FFID value is : $FFID"
while [ $FFID = `ls -1rt $1 | grep -i ffid | tail -1` ]
do
hexdump -e "16 \"%_p\" \"\\n\"" $FFID | sed -n '68,73p' > list
done
for filename in 'cat list'
do
cat list.txt | sed -n 1p | cut -c13-14 = $hh1
cat list.txt | sed -n 1p | cut -c15-16 = $mm1
cat list.txt | sed -n 2p | cut -c1-2 = $ss1
done
$time1 = "$hh"":""$mm"":""$ss" ;
$time2 = "$hh1"":""$mm1"":""$ss1" ;
$former_seconds = $(date --date= "$time1" +%s);
$later_seconds = $(date --date= "$time2" +%s);
$time_delay = ( "$later_seconds" - "$former_seconds" )
$wb_time = ( "$wd" * 1.33 )
if
(("$wb_time" + "$time_delay")) < 12.0
then
echo "please slow down"
fi
if [ -e EOL.ffid ]
then
echo "EOL.ffid detected, exiting script"
exit
fi
done
I am not able to figure out why the hexdump code is giving me an error . Please help .

You are missing the do in your for loop:
for file in /argus/raid2/"$line"/*.ffid
do
hexdump -e "16 \"%_p\" \"\\n\"" $FFID | sed -n '68,73p' > list1
done

Related

Remove text from a txt file that is in an array

So I have these two functions: cMinOption and cMaxOption.
cMinOption puts all words from pt.stop_words.txt into myArray.
cMaxOption shows a list of words from ficha01.pdf.txt, including on that same list of words from pt.stop_words.txt.
I want to know how can I delete the words from the array I created and delete those words from the list that appears in the function cMaxOption.
cMinOption(){
declare -a myArray
mapfile -t myArray < pt.stop_words.txt
sed -i 's/myArray/""/g' ficha01.pdf.txt
sed -e 's/[^[:alpha:]]/ /g' ficha01.pdf.txt | tr '\n' " " | tr -s " " | tr " " '\n'| tr 'A-Z' 'a-z' | sort | uniq -c | sort -nr | nl | head -n 7
for ((i=0; i<204; i++)); do
echo "Element [$i]: ${myArray[$i]}";
done
}
# Called when -C is passed as argument
cMaxOption(){
# Check if the file passed in $1 is a PDF file
if [ $(head -c 4 "$1") = "%PDF" ]; then
pdftotext $1 $1.txt
echo "'$1': PDF file";
file="$1.txt"
else
echo "'$1': TXT file";
file="$1"
fi
echo "[INFO] processing '$file'"
echo "STOP WORDS will be counted"
echo "COUNT MODE"
sed -e 's/[^[:alpha:]]/ /g' $file | tr '\n' " " | tr -s " " | tr " " '\n'| tr 'A-Z' 'a-z' | sort | uniq -c | sort -nr | nl | head -n 7
mv $file result---$file
echo "RESULTS: 'result---$file' "
ls -l result---$file
echo -e " $(sort -u result---$file | wc -l) distinct words"
}

How to use cat and EOF in gnuplot to create a file while executing the gnuplot script

I want to make a file, for.sh, in the gnuplot script during its execution. The new file then will be called in the gnuplot script as
set xtics (`(sh for.sh)`)
The contents in for.sh should be these.
#!/bin/bash
rm Final-X-ticks.dat
KPATH=data1
TICK_position=data2
sed -n '/crystal coordinates with respect/,/REPRODUCED(TRANSFORMED) DATASET/p' $KPATH | sed '/crystal/d' | sed '/REPRODUCED/d' | awk '{print $4}' | sed -r '/^\s*$/d' > symbl.dat
line=$(cat symbl.dat | wc -l)
for i in `seq 1 1 $line`
do
echo " '{/Times-New " > symbl-$i.dat
cat symbl.dat | tail -n $line | head -n "$i" | tail -n 1 >> symbl-$i.dat
echo " }'" >> symbl-$i.dat
grep -i "coordinate" $TICK_position | awk '{print $NF}' | head -n "$i" | tail -n 1 >> kpoints-$i.dat
cat kpoints-$i.dat | tail -n 1 | awk 'BEGIN { ORS = " " } { print }' >> symbl-$i.dat
echo " ," >> symbl-$i.dat
cat symbl-$i.dat | awk 'BEGIN { ORS = " " } { print }' | awk '{gsub(/Times-New[ \t]+(G|\$\\Gamma\$)/, "Symbol G")} 1' | awk 'BEGIN { ORS = " " } { print }' >> Final-X-ticks.dat
done
rm symbl-* symbl.dat kpoints-*
I tried with
cat > for.sh <<EOF
above contents
EOF
but it gives me error
cat for.sh << EOF
^
"plot.gnu", line 19: invalid command
You can use a datablock to hold the text, then print it out. For example,
$MYSCRIPT <<EOF
#!/bin/bash
rm Final-X-ticks.dat
...
rm symbl-* symbl.dat kpoints-*
EOF
set print "for.sh"
print $MYSCRIPT
set print
set xtics (`(bash ./for.sh)`)

variable not holding output of command

The output of $ip coming blank
#!/bin/bash
for i in illinrcmsg{002..003}
do
echo " ####################### $i #################### "
ssh -o StrictHostKeyChecking=no $i "
echo $i
cp /etc/hosts /etc/hosts_bak
ip=`ifconfig | head -n 2 | tail -n 1 | awk '{print $2}' | cut -d':' -f2`
echo $ip
echo "$ip $i.corp.amdocs.com $i" >> /etc/hosts
"
done
I am trying to fix /etc/hosts entry on multiple servers with a bash script, but it is dumping on hostname values on the file.
This worked:
#!/bin/bash
for i in illinrcmsg{002..003}
do
echo " ####################### $i #################### "
ssh -o StrictHostKeyChecking=no $i "
echo $i
cp /etc/hosts /etc/hosts_bak
#ip=`ifconfig | head -n 2 | tail -n 1 | awk '{print $2}' | cut -d':' -f2`
#echo $ip
echo "`nslookup illinrcmsg002 | tail -n 2 | head -n 1|awk '{print $2}'`
$i.corp.amdocs.com $i" >> /etc/hosts
"
done

Need help in solving "unexpected end of file" exception?

I am trying to transform below 2 statements into a shell script
cat all5.log | grep 'Opened\|Closed'> all.log
awk -F ' ' '{print }' all.log | sort | uniq > uniqueFiles.txt
Here is monitorFd.sh bash script
#!/bin/bash
if [ "" != "" ]; then
cat | grep 'Opened\|Closed' > temp.log
awk -F ' ' '{print }' temp.log | sort | uniq > uniqueFiles.txt
while IFS='' read -r line || [[ -n "$line" ]]; do
cmd1=`cat | grep Opened | grep $line | sort | wc -l`
cmd2=`cat | grep Closed | grep $line | sort | wc -l`
echo 'Opened: '$cmd1', Closed: '$cmd2' '$line
done < "uniqueFiles.txt"
rm -f temp.log
else
echo "No target file provided. (hint: trace dump of file-leak-detector.jar)" #syntax error: unexpected end of file
In notepad++ I changed this file to be of UNIX format. Also changed permission to +x, but I am getting below exception.
monitorFd.sh: line 16: syntax error: unexpected end of file
What is wrong with this program?
The Syntax for if in bash is if ... else/elif ... fi. So just add a fi at the end of your file.

Check MAC from log

I currently have a script that checks the MAC address, tt looks like this
"m"|"-m" )
if [ ! -n "$2" ]
then
echo "Enter MAC address"
exit 0
fi
out1=`cat $dhcp_files/* | grep -i "$2" 2>/dev/null`
ip=`cat $dhcp_files/* | grep -i "$2" | awk '{print $8}' | sed s/\;//g 2>/dev/null`
out=` grep -i $ip $shapy/* | awk '{print $8}' 2>/dev/null`
echo -en ''$out1' on '$out' \n'
this is done like that: ./mac_check -m 00:00:00:00:00:00
The result of this script:
host Jon_Rosewelt_6_5 { hardware ethernet 00:1d:4e:b5:d4:10; fixed-address 192.168.101.19; } on eth4
but I would like to do to the script received any form of mac address
aka. ./check_mac -m 001d.4eb5.d410 **or** 001d4eb5d410 **or** 00-1d-4e-b5-d4-10
How can I do that?
With GNU sed and Solaris sed:
echo 001d.4eb5.d410 | sed 's/[^0-9a-f]//g;s/../&:/g;s/:$//'
echo 001d4eb5d410 | sed 's/[^0-9a-f]//g;s/../&:/g;s/:$//'
echo 00-1d-4e-b5-d4-10 | sed 's/[^0-9a-f]//g;s/../&:/g;s/:$//'
echo 00:1d:4e:b5:d4:10 | sed 's/[^0-9a-f]//g;s/../&:/g;s/:$//'
Output:
00:1d:4e:b5:d4:10
00:1d:4e:b5:d4:10
00:1d:4e:b5:d4:10
00:1d:4e:b5:d4:10
With your code:
"m"|"-m" )
mac="$2" # added
if [ ! -n "$mac" ] # changed
then
echo "Enter MAC address"
exit 0
fi
mac="$(echo "$mac" | sed 's/[^0-9a-f]//g;s/../&:/g;s/:$//')" # added
out1=`cat $dhcp_files/* | grep -i "$mac" 2>/dev/null` # changed
ip=`cat $dhcp_files/* | grep -i "$mac" | awk '{print $8}' | sed s/\;//g 2>/dev/null` # changed
out=` grep -i $ip $shapy/* | awk '{print $8}' 2>/dev/null`
echo -en ''$out1' on '$out' \n'

Resources