Looking for Scripting Help

July 24, 2018 at 10:39:35
Specs: CentOS 6/7
I have scripts that run off my virtual device using something called an RSA key so that my passwords can work on all devices.

For example:

========================EXAMPLE SCRIPT
#!/bin/bash
read -p "Enter first system number: " startsysnum
read -p "Enter last system number: " stopsysnum

echo ""
echo ""
echo IB STATUS of the following nodes:

for x in `seq $startsysnum$stopsysnum`
do for n in 1 2
do ssh -i /home/metheuser/.ssh/me_id_rsa root@system$x-n$n "ibstat |grep State"; done; done
========================

My issue is with this command:
df; find /tmp -type f -mtime +7 -name '*.tar' -execdir rm -- '{}' \ ; df"; done; done

========================CLEAN SCRIPT
#!/bin/bash
read -p "Enter first system number: " startsysnum
read -p "Enter last system number: " stopsysnum

echo ""
echo ""
echo IB STATUS of the following nodes:

for x in `seq $startsysnum$stopsysnum`
do for n in 1 2
do ssh -i /home/metheuser/.ssh/me_id_rsa root@system$x-n$n "df; find /tmp -type f -mtime +7 -name '*.tar' -execdir rm -- '{}' \ ; df"; done; done
========================

I get these errors:

[metheuser@vd-metheuserscripts]$ ./clean.sh
Enter first system number: 2479
Enter last system number: 2479
./clean.sh: line 8: syntax error near unexpected token `done'
./clean.sh: line 8: `do ssh -i /home/metheuser/.ssh/me_id_rsa root@system$x "df; find /tmp -type f -mtime +7 -name '*.tar' -execdir rm -- '{}' \ ;; df"; done; done'

Earlier I tried it with one "done" and got this error:

find: missing argument to `-execdir'

This works individually (the df works so this is the focus here):
find /tmp -type f -mtime +7 -name '*.tar' -execdir rm -- '{}' \;

That command has to have that semicolon on its own for it to work, else it hands.

Any thoughts to get that CLEAN script to work correctly with all that punctuation in it?

Thanks.

I reply as fast as I can, but it could be hours or months.


See More: Looking for Scripting Help

Reply ↓  Report •

#1
July 24, 2018 at 20:59:41
for x in `seq $startsysnum$stopsysnum`
do for n in 1 2
do ssh -i /home/metheuser/.ssh/me_id_rsa root@system$x-n$n "df; find /tmp -type f -mtime +7 -name '*.tar' -execdir rm -- '{}' \ ; df"; done; done

Not exactly an expert on bash, but I'm pretty sure "do" needs to be its own statement. Try "do;"?

How To Ask Questions The Smart Way

message edited by Razor2.3


Reply ↓  Report •

#2
July 26, 2018 at 09:33:27
Darn, my original post has an error in it. I can not seem to edit it so let me repaste the script I am having issues with without the extra line that should not be in there, along without the "df" commands.
==============================
#!/bin/bash

read -p "Enter first: " start
read -p "Enter last: " stop

for x in `seq $start $stop`

do ssh -i /home/me/.ssh/id_rsa root@system$x "find /tmp -type f -mtime +7 -name '*.tar' -execdir rm -- '{}' \;"; done; done
==============================

Now, on the system itself,
find /tmp -type f -mtime +7 -name '*.tar' -execdir rm -- '{}' \;
works fine (and it needs that semicolon else it hangs).
Just in that command it will not as it produces the mentioned errors.

I reply as fast as I can, but it could be hours or months.

message edited by CPU13


Reply ↓  Report •

#3
July 26, 2018 at 10:40:47
Now you have one too many "done"s, and you still haven't changed "do" to "do;"

The find command is irrelevant. At this stage of execution it's only a string being passed to ssh, and the error is not coming from ssh.

How To Ask Questions The Smart Way


Reply ↓  Report •

Related Solutions

#4
July 26, 2018 at 10:57:37
I just tried that adding a semi in front of "do" and removing one "done" but I still get the errors of an unexpected token.

I coped the basics of this from that first script, which works just fine.

for x in `seq $startsysnum$stopsysnum`
do for n in 1 2
do ssh -i /home/metheuser/.ssh/me_id_rsa root@system$x-n$n "ibstat |grep State"; done; done

That one there does not have all the flags and such as the cleaning script am trying to do.

Hmmmm....

I reply as fast as I can, but it could be hours or months.


Reply ↓  Report •

#5
July 27, 2018 at 07:19:00
Okay, falling back onto my CMD experience, it's time to try more backslashes at '{}' \". My guess is we need 2-3 backslashes, like '{}'\\\"

EDIT: Wait, I just noticed the space between the backslash and the semicolon. That space needs to be removed.

How To Ask Questions The Smart Way

message edited by Razor2.3


Reply ↓  Report •

Ask Question