To Send A While Loop To Background

Hi All,

i got a question (noob of course), stuck with my little script when i try to send this while loop into background.

cat stogrpexport | awk 'NR>1' | while read id2 &
do
echo $id2 >> stat.out &
symstat -sid 1075 -i 5 -c 5 -dev $id2 >> stat.out &
done


symstat is a vmax storage command for stat reading which taking long time to complete. is there any better wat to re-write this loop? thanks.


Similar Content



Script While Loop

Hello,
I'm working on a shell script that needs to read the a file (file1) a batch (read 2000 lines at a time) and then write those lines to seperate file which I'm using to run ldapmodify command. I need to check some other file size and once this file less than 200kb, i would need to run second batch and so on until file1 is empty.
Quote:
#!/bin/bash
set -x
filesize=200
server=10.11.xxx.xx
filename=fileimport.txt
taofile1=687686.txt
taofile=/var/opt/$taofile1

stty -echo
echo -n "Enter password: "
read passwd
stty echo
context="cn=user1,ou=org1,ou=org2,o=org"
if [[ -s "$filename" ]];then
for lines in $filename
do
head -99997 fileimport.txt >> ldapreadd.ldif && sed -i '1,+99996d' fileimport.txt
if [ -s ldapreadd.ldif ];then
ldapmodify -h $server -p 389 -D $context -w $passwd -v -x -f ldapreadd.ldif &> /dev/null
echo "LDIF script is running. Please wait..."
sleep 60
if [ -f "$taofile" ];then
taofilesize=`stat -c %s ${taofile}`
# if [ "$taofilesize" -ge 200 ];then
while [ `stat -c %s ${taofile}` -ge 200 ]
do
echo " Driver is processing LDIF file. Please wait..."
sleep 60
done
fi
rm -rf ldapreadd.ldif
fi
done
else
echo "$filename file is empty. Exiting script..."
exit
fi

I have 2 issues here. first one script is not reading exact lines as specified. Some times its reading more lines some times less lines. Second issues once it run the first batch, script is exiting. Please advise.

Bash Shell Script Help Please

I want to write a bash shell script to execute a command for one minute then stop that command (ctrl c) pause for 10 seconds then run another command for one minute then stop that command pause for 10 seconds then go back to the begining of the script and loop indefinetly.

First I want to run this command for one minute;

reaver -i mon0 -c 6 -b "mac address" -a -vv

stop previous command and pause for 10 seconds

Then run this command for one minute;

airodump-ng -i mon0

stop previous command and pause for 10 seconds

Then recall reaver command and continue to loop through until reaver spits out result.

I imagine I will need to create a function for each command, an if statement and an ifelse statement and I will need the break and sleep commands. but I am not sure about the syntax, PLEASE HELP THIS NOOB!

Need Suggestions To Loop A Video Converted From An Animated Gif

hi

I have an animated gif file which I converted into a video. The video plays for one second. How can I loop it to play for 15 seconds. here is what I have tried.

Code:
ffmpeg -i 3.gif -loop input -t 15  -c:v mpeg4 -b:v 1000k out.avi

thanks

While Loop Not Working

Hey, not sure if this is the best place however thought id ask my question ..

My while loop below doesnt return as id expect :

while [[ ! "$RES" =~ (1|2|3|4|5|6|7|8|9|x|10)$ ]]
do
read -p "Please select an above option : " RES || exit
done

if [[ "$RES" =~ 1 ]]
echo "Option 1 Selected"
and so on through all my results

This goes on and works all the way up to 10.

If i select option 10 it runs option 1.

Any idea how to make sure when i select option 10 it runs it not 1.

Recurring Startup Application

Hi
Kindly refer to following post:
http://www.linuxforums.org/forum/pro...tml#post954718
Here, at post #4, solution given by "LSalab" worked for me. So I added it to startup applications in my cinnamon desktop. But the problem is that, it works only once after every login (when the battery gets lower than 10% so it informs me), and if I charge the battery and again it reaches that threshold point of 10%, the system does not inform me, which means that the startup script only executes once.
here is the script:
Code:
#!/bin/bash
while [[ `acpi | cut -d ' ' -f 4 | grep -Po '\d+'` -gt 10 ]]
do echo -ne "\r`acpi`"
sleep 5
done
notify-send -t 60000 'Low Battery' 'Battery charging of your system is below 10%. Kindly Plug charger. Thanks.'
echo ''
mplayer /usr/share/sounds/freedesktop/stereo/phone-outgoing-busy.oga -loop 0

So my question is that, how can I make this script recurring at every threshold level?
Regards

Problem W/.bash Script... Need Help

I'm trying to loop through a query in SQLDeveloper by passing the query a different Period and I'm having a problem getting the syntax correct.

Individually the following works correctly on its own:

Code:
#!/bin/bash
 for i in `seq -f "%02g" 1 5`;
    do
    echo $i
 done

$ ./test.sh
1
2
3
4
5

the following also executes correctly:

Quote:
sqlplus table1/$userpass@Mytable <<EOF
@./sqlcode.sql $i
EOF
but when I try to wrap the loop around my sqlplus command

Code:
#! /bin/sh
userpass=read
for i in `seq -f "%01g" 1 3`;
  do
        sqlplus -S  table1/$userpass@Mytable <<EOF
        @./sqlcode.sql $i
        EOF
done

I get the following error:

./test.sh: line 13: syntax error: unexpected end of file

Does anyone have any ideas on what's going on?

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.

Need Help To Get The Available Hosts Among Many Hosts

I have many hosts as following. But those hosts are dual operating system (Linux and Windows). I always run program background. If someone is using Linux, it is fine. But if someone is using windows or the host is offline. Then, I cannot use ssh. The way I do preiviously is first ssh one by one. And then find the hosts which are offline or windows. And write them down one by one. And then ssh to hosts except them. Let us assume the number of programs is less than the total available hosts. Can someone write a shell script to output the all available hosts to a file like "host_available"?
Here is the host file.
https://www.dropbox.com/s/vbz6w864y3...tlist.txt?dl=0
I am using ssh to connect the computers on campus. If the computer I am trying to connect is offline or using windows, the ssh will take long time, and finally it will failed. I write a shell script to generate the hostlist
Code:
#!/bin/bash
for i in `seq -w 1 28`
do
echo "c15-0330-$i.ad.mtu.edu"
# I would like to add a command here to see whether ssh c15-0330-$i.ad.mtu.edu it succeeds or not. And then output a #file which contains the all available host.
done
for i in `seq -w 1 20`
do
echo "c28-0112-$i.ad.mtu.edu"
done
for i in `seq -w 1 20`
do
echo "c28-112a-$i.ad.mtu.edu"
done

I do not how to set a certain time to see whether connection is successful or not (see the comment in the shell script).

Bash Background Changing Script

Hey internet people i have been trying to create a bash script that will change my desktop background, boot splash image, and the gdm3 login background. If one of you could write it for me or atleast point me in the right direction i would greatly appreciate it. Im currently running tango studio (based on debian)

How To Return From Shell 'read' Command Passed In Expect Script?

I have a shell script that calls an expect script I wrote to ssh login to another host and get user input regarding that host's network configuration. I pass four arguments to the expect script: the remote host ip address, the username, the password, and the list of commands to run. My expect script is below:

#!/usr/bin/expect
# Usage: expectssh <host> <ssh user> <ssh password> <script>

set timeout 60
set prompt "(%|#|\\$) $"
set commands [lindex $argv 3];

spawn ssh [lindex $argv 1]@[lindex $argv 0]

expect {
"*assword:" {
send -- "[lindex $argv 2]\r"
expect -re "$prompt"
send -- "$commands\r"
}

"you sure you want to continue connecting" {
send -- "yes\r"
expect "*assword:"
send -- "[lindex $argv 2]\r"
expect -re "$prompt"
send -- "$commands\r"
}

timeout {
exit }

expect -re $prompt
send -- "exit\r"
}

The script runs well, except that if I send a command such as 'read' that requires user input, the script does not continue or exit after the user presses enter. It just hangs.

The commands I pass to the expect script and it's call are as follows:
SCRIPT='hostname > response.txt;netstat -rn;read net_card?"What is the network interface card number? " >> response.txt; read net_mask?"What is the subnet mask? " >> response.txt'

/usr/bin/expect ./expectssh.exp $hostip $usr $pswd "$SCRIPT"

Any suggestions on how I can pass a command to my expect script that requires user input without it hanging?

On a side note because I know it will come up - I am not allowed to do key-based automatic SSH login. I have to prompt for a username and password, which is done from my main shell script.

Thanks for any suggestions and help you can provide!