Languages and Scripting

With one word is o.k., with more than 1 word is not ok !!!

 
SOLVED
Go to solution
Manuales
Super Advisor

With one word is o.k., with more than 1 word is not ok !!!

Hi..
i'm doing a script which is going to verify when a process is down.
All proceses are in a file called PROCESOS.txt, it was crated whit result of:
ps -fea > PROCESOS.txt

now, when a process is only 1 word there is no problem and this word is kept in a variable named "proceso" but when are more than 1 it can not to keep the words in the variable proceso , i'm attaching images about script and the run
where it says " el valor de fin es 11" you can see when "k vale 9" is not doing things (echo commands) progrramated in script.
My doubt is ,why can not all words in variable proceso ?

Thanks, Manuales.
7 REPLIES 7
Pete Randall
Outstanding Contributor
Solution

Re: With one word is o.k., with more than 1 word is not ok !!!

I can't open your attachment so I'm guessing that you are assigning the lines of text from PROCESOS.txt to a variable and you're probably not using quotes, so you're only getting the first word of the line. Try using quotes.


Pete

Pete
Manuales
Super Advisor

Re: With one word is o.k., with more than 1 word is not ok !!!

Thanks Pete,i have alredy found the solution:

before:
"fin" variable cold be 10 or more than 10
....
....
fin=$(echo $proc | wc -w )
.....
.....
case $m in
[9-$fin])....
...... ;;
esac


After:
fin=$(echo $proc | wc -w | cut -c1)
fin2=$(echo $proc | wc -w | cut -c2)
....
....
case $m in
9 | $fin[0-$fin2])...
....
esac

That was the solution !!!
i was using other sintax with case comand ...

Thanks, Manuales.





Manuales
Super Advisor

Re: With one word is o.k., with more than 1 word is not ok !!!

thanks !!!
D Block 2
Respected Contributor

Re: With one word is o.k., with more than 1 word is not ok !!!

Can you post your script here and not in the attachment. And what is the end result you are trying to do ?

Input: take in the command and all the arguments and save into a file.

Output: ??

you can try the "x" option to ps -efx
which shows all of the process arguments and options.
Golf is a Good Walk Spoiled, Mark Twain.
Manuales
Super Advisor

Re: With one word is o.k., with more than 1 word is not ok !!!

Hi Tom when i finish with script i'll atach it, probably it interest to you .. o.k.??

Do you have any mail to email it to you ???
Manuales.
D Block 2
Respected Contributor

Re: With one word is o.k., with more than 1 word is not ok !!!

case in shell
nice job.
Golf is a Good Walk Spoiled, Mark Twain.
D Block 2
Respected Contributor

Re: With one word is o.k., with more than 1 word is not ok !!!

case statements can be very tricky.. wish you the best..
Golf is a Good Walk Spoiled, Mark Twain.