Ubuntu :: Bash Menu Option Loop
Mar 19, 2010I am trying to make a bash menu that loops with options but it does not work as I want:
Code:
I want to make it read an option and do the action then return to menu.
I am trying to make a bash menu that loops with options but it does not work as I want:
Code:
I want to make it read an option and do the action then return to menu.
This gives a selection menu where you choose an option, and it should continue. I have several of these as part of a much larger script, but something is wrong with this while loop.
Code:
VARIABLEINPUT="1"
if [ $VARIABLEINPUT == "1" ] ; then
echo -e "${YELLOW}How often would you like the automatic update and maintenance to occur after the installation?:
${RED}1)${WHITE} Hourly
${RED}2)${WHITE} Daily
${RED}3)${WHITE} Weekly
${RED}4)${WHITE} Monthly
"
[Code].....
A very simple loop that uses a variable from earlier in the script to adjust variables for later in the script. For some reason, this while loop will not end - I've noted where with echos.
I have a while loop in a file that looks like:
Code:
while IFS=":" read name script
do
su
exit
[code]....
Where I redirect the file into the loop, for some reason, I can't do an su when I redirect a file like that. I get the error, "su: must be run from a terminal." Why is this? How can I fix it?
What is the difference between For and While when creating loops in bash scripting?
View 1 Replies View RelatedI have bash 4.0. I used the following for loop example, but all it outputs is "{1..10} instead of the actual numbers one through ten. why?
Code:
for a in {1..10}
do
echo -n "$a "
done
I'm not overly great with bash scripting. I do more batch file stuff for Windows than anything else but I'm trying to branch out a bit. (Frankly, I'd love to do this in Ruby but I'm not there yet...) Maybe I'm not using the correct terminology and that's why my searches are coming up useless...
Anyway, I have a script that does some work with HandBrake. Although it deals with HandBrake, I think the issue is not with HandBrake itself. The issue: I had a simpler script which worked fine but it would give me an MP4 with a file name of: Some Movie Name.iso.mp4 and it would still play but I wanted to get rid of the .iso in the file name. I also wanted to drop it into another directory during the encoding. That's why you see a $source & a $destination variable.
handbrake.sh
Code:
#!/bin/bash
source=/media/data/movies
destination=/media/data/movies/mp4s
[Code]...
I want to figure out what is going on in this small script.Its really strange.I think its the infinite loop again.All I want to do is to collect some data from the zenity dialog box in an array and then echo it.Here is the code
Code:
#!/bin/bash
#export PS4='+${BASH_SOURCE}:${LINENO}:${FUNCNAME[0]}: ' debugging info
[code]...
Totally new to programming (as of this morning) so please bear with me I have a bash script that stops working after the first while loop.
#part 1
While
doThisThatThe Otherdone
#part 2
While
doMOreMoreMoredone
Every arguement above the first loop completes (including the first loop itself) but anything below (incuding the second while loop) doesn't finish. I know that it isn't a problem with an unending loop... it seems to be something about the While loop that I'm not understanding... but I can't figure it out. I just need arguments below the first while loop to take place.
I have to format 4 years worth of awstats data "static" for a client and then move it to their new server.I don't want to run the commend to do this 48 times. If possible I would like to use a bash script that uses the folders in a directory so the script knows which year-month to do this for me and which folder to place the output in.
View 5 Replies View RelatedI ran across some odd behaviour using ssh in a bash script. I am hoping someone can explain it to me. I have a file called /home/user/hosts.
Code:
$ cat /home/user/hosts
host1
host2
host3
What I want (for this example anyway) is to run a script that checks this file and for each entry in this file it should log into that host and run a command. I have a script called testssh.sh.
Code:
$ cat /home/user/testssh.sh
#!/bin/bash -
somefile='/home/user/hosts'
[code].....
The oddity that wasted an hour of my day and the question I have for this group is, what is it about ssh that breaks the while loop? It obviously runs through once and checks the first host, just never checks any of the others. I checked exit status's and all kinds of verbose data and I could not figure it out.
I'm writing a mass snmp toner check which polls any toners available to be snmp polled, however when using a loop statement I get the results on different lines; which sounds good, however the tool I use to check with (nagios) ignores the new lines.
Is there any way I can get the output on one line? Also, I need to raise a fault if any of the toners are below a specific level (with nagios you raise faults with the exit code) - any way I can do this without exiting the loop. Code below with bits and bobs commented out.
Code:
check_ink_levels ()
{
for ID in $INKS
do
[Code].....
The script that Iam trying to write is running a for loop and reading line by line from a text file. inside this for loop i would like to execute update SQL statement .
a pesudo code is
Quote:
`$ISQL -U $username -P $Password -D $Dbname -I $INTERFACE <<QRY
for id in $idlist #idlist iam reading from a file
[code]...
I have a file like below:
PU12829,24869;PD15733,24869;PD15733,19785;PD12829,19785;PD12829,24869;
PU4599,20915;PD9924,20915;PD9924,18898;PD4599,18898;PD4599,20915;
PU12829,24869;PD15733,24869;PD15733,19785;PD12829,19785;PD12829,24869;
PU4599,20915;PD9924,20915;PD9924,18898;PD4599,18898;PD4599,20915;
PU1723,3423; #this line is ignored to short
[Code]...
What I'm trying to do is while true, cut each line from file that begins with PU and thats longer than 12 characters and write to a increasing numbered file for each line. Stating with object1 etc.
I know of 4 different ways to use a for loop:
1. for I in {1..10}; do echo $I; done|
2. for I in 1 2 3 4 5 6 7 8 9 10; do echo $I; done|
3. for I in $(seq 1 10); do echo $I; done|
4. for ((I=1; I <= 10 ; I++)); do echo $I; done
I have a script which uses the 1st form of for loop. I'm trying to modify it to use a variable instead of a static hard-coded value in the section that controls the looping.of the for loop.
I've tried all different ways of quoting and escaping the variable, and the problem is that the quoting chars and escape char are being translated and passed into the loop along with the value stored in the variable.
For example, to change the start value of 1 to whatever value I want passed in through a variable:
Change:
I have tried: {{$a}..10} and {`$a`..10}, to have the variable evaluated first.
I have tried using the eval() function.
I have tried single and double quotes and the backslash escape character.
Nothing I've tried works. It's probably a syntax error.
nested loop in ''Bash-Scripting in Linux'' ?What's wrong with my code:
for x in `seq 0.75 0.01 0.95`
do
for y in `seq 0.20 0.01 0.40`
[code]....
Am new in bash scripting, presently I have 2 files and i need to create a file reading from these 2 files. I was trying to work with 2 for loops, but I can see like once its executing 1st outer loop then all inner loop, then next outer loop+ all inner loop. How can i get result like 1 outer loop, 1 inner loop then 2 outer loop,2 inner loop etc. Below is my prog
#!/bin/bash
rm d
for i in `cat a`
do
echo "dn:$i >> d
for j in `cat b`
[Code]...
As you can see on the output of the script, the two 'testing echoes' I do at the end don't print anything.That's the point, I do NEED this array further in my script.I'd understand my "param" var is local to the for, but is the other one too ? I tried to use "declare -a file" before the for, but i get same exact result !
View 2 Replies View RelatedNever mind, I figured it out myself. Firstly, the old version of BASH I'm using doesn't support
Code:
for i in {1..27}
So I had to use
Code:
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
Secondly, it was simply
Code:
#!/bin/bash
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
do
[code]....
So I need to write a bash script that can read lines and column 3 from a file. It needs to start on line 16 and read every 20th line starting from there. But the value that it reads needs to be checked, should it be too great I need it to shut the program down.I'm pretty new to bash, but my ultimate goal is being able to safely run a program on a GPU for an extended period of time with out worrying about it overheating. I have a command that outputs information from the GPU every second, and I can save this to a file. So all I really need is something to read and check that file, I played around a bit with the awk command and can't get it to work within my for loop with dynamic variable.
View 7 Replies View RelatedI need to know how to assign a result from a select. I am clueless on the sytax. I am trying this in bash. Maybe I am not assigning the array right. It gives me the whole row in the echo instead of just field a. How do I get fieldA = a in the select. Note script was stripped for security on database info but the syntax is same.
Code:
#!/bin/sh
results="$(mysql --user ${DB_USER} -p${DB_PWD} ${DB_NAME} -Bse 'select a,b,c,d from tblMytable')"
for rows in "${results[@]}"
do
fieldA=${rows[0]};
echo ${fieldA};
done
I'm trying to code the following WHILE loop in Bash:
While [string1 is non zero] and [string2 is non zero] and [counter < max]
Do
...
Done
I can't get the syntax right. I've tried:
Code:
while [ -n "$STRING1"] -a [ -n "$STRING2"] -a [$COUNTER -lt $MAX ]
But I get 'Too may arguments'
How do I get this loop to stop on each increment? This script does work but I would like it to stop at each increment, remember what the value of $n is, then continue until it gets to 7. I have worked so hard on this. My brain is hurting now.
[Code]...
I have a bash variable where the content looks like this where ;f1; and ;f2; are delimiters:
;f1;field1value1;f2;field2 value1 ;f1;field1value2;f2;field2 value2 ;f1;field1value3;f2;field2 value3
So what I need is to extract and put into variables each combination of f1 and f2 in a loop to something like that:
#first pass of the loop I need:
f1=field1value1
f2=field2 value1
#second pass of the loop I need:
f1=field1value2
f2=field2 value2
# third pass of the loop I need:
f1=field1value3
f2=field2 value3
I have Windows XP as well as Ubuntu in my desktop. I would like to temporarily disable XP for a month or so, so that One cannot see Windows XP appearing in the grub menu list or during the boot. Is there is any option to edit the grub menu?
View 1 Replies View RelatedI downloaded the 32bit iso from the ubuntu website and wrote it to disc using imgburn.
The problem is that when i boot from cd i get the loading splashscreen with the 4 dots flashing then it loads the ubuntu background and my mouse curser spins around for awhile then tells me the installer encountered and unrecoverable error and a desktop session will now be run so you may investigate and problem or try installing again. When it reboots it asks for a username and password. i use ubuntu and blank and then it does a loop and the logon menu comes up again.
the computer is an old acer aspire running xp home sp2
i tried it on another computer a dell laptop running vista and it worked fine and can up with the menu and i clicked try now and it booted into the gui.
I'm trying to read content of file to variable and use this variable in for loop. The problem is, when I have c++ comment style in file - /*. Spaces in line are also interpreted as separated lines.
For example:
Code:
Changing $files to "$files" eliminate these problems but causes that whole content of variable is treated as one string (one execution of loop).
I've had two students report a problem whereby Ubuntu does not show up as a menu option in Grub. Both systems used Wubi installations of Ubuntu 10.04 Desktop for x86 on Windows XP. In both cases, Ubuntu completed the installation process. Upon reboot, we have the options to choose between Windows XP and Ubuntu. However, once we enter into Grub, only the Windows XP option shows.
View 8 Replies View Relatedi have a dual boot. i loaded 9.1 on one disk and windows xp is on another. grub worked fine. i downloaded 10.4 and i must have selected the wrong option cause when i restarted it dropped me into a shell. i reloaded 9.1 and wiped out 10.4. again i must have selected the wrong option cause i get the grub menu with an option for windows but nothing happens. 9.1 comes up alright and i can select windows office files from ubuntu.
View 1 Replies View RelatedI installed Ubuntu onto a separate partition I have. Now however when i boot up, Grub (v1.98 ) gives m 5 options.
Ubuntu, with Linux 2.6.35-22-generic
Ubuntu, with Linux 2.6.35-22-generic (recovery)
Memory Test (memtest86+)
Memory Test (memtest86+, serial console)
Windows Recovery Environment (loader)
With no Vista option.
When I run the recovery environment however, it runs just my regular vista boot would have. Is this just a name issue? Ideally I would like to have my Vista option back.
I increasingly use Ubuntu so swapped SATA ports 1&2 around so now 7 boots from BIOS F11 pop out menu. Windows did not complain so far but hibernate is missing from Ubuntu's power down options. I installed Ubuntu Tweak, but cannot see an option to re-enable. Is this something to do with the swapped HDDs &/or the swap partition? Or more likely a recent update?
View 3 Replies View Related