Bash script to create bash script
I have a csv that contains 3 columns and 65 rows. I need to make a script from each row.
Here is a sample of the scv filename_1.ga10 monthend/foo/bar/ 192.168.1.100:bar/ Here is my code Code:
#!/bin/bash sh -x shell.sh I get the following jgreene@jgreene-desktop:$ sh -x shell.sh + i=0 shell.sh: line 11: syntax error: unexpected end of file Can anyone tell me what I am doing wrong? |
The while loop is not complete. The do and done statements refer to the for loop. Hence the "unexpected end of file" error. By the way, I would check the logic more carefully: probably you don't need the inner for loop (or the outer while loop) if you want to parse the entire file one row at a time.
Edit: you may also consider to do a simple and pure awk code, using redirection inside awk (same syntax as shell redirection). |
Thanks for the quick reply.
If I run the awk code on its own I get a single script with all 65 actions in it instead of 65 scripts. I'm very new at scripting. I understand what you wrote but I don't know what to do about it. |
Quote:
Code:
gawk '{print something > $1".sh"}' somefile |
Ok, so this is what I have so far...
Code:
#!/bin/sh only problem now is that I can't get the script to name the output file from $1 in the second awk statement. it tells me awk: cannot open par410p1.ga08,monthend/gsa/rco/,192.168.1.100:rco/ (No such file or directory) thoughts??? |
Well... this is not exactly what I meant. Awk parses the text file, executing all commands on each line, so maybe there is no need to loop over the file with shell commands (if I correctly understand your question). So, why not simply...?
Code:
awk -F, '{print "#!/bin/sh\n#GETTInG FILE\nscp root@192.168.1.150:/data/"$2 $1 $2"\n#PUTTING FILE\nscp "$2 $1" root@"$3 > $1".sh"}' gsmd.csv |
Quote:
You gotta be kidding... that is exactly what I was looking for. You da bess.... Thanks! |
You're welcome! I hope it was clear the whole frame and the meaning of the errors you got before reaching the solution. Maybe, you will check again the syntax of your awk command, since it looks like the obtained scripts will not work as you expect, he he he... :):) Cheers!
|
It was sort of clear. I understand (sort of) why it didn't work but I had no idea how to resolve it
You are right... that syntax won't work but this #!/bin/sh awk -F, '{print "#!/bin/sh\n#GETTING FILE\nscp root@192.168.1.150:/data/"$2 $1" "$2 $1"\n#PUTTING FILE\nscp "$2 $1" root@"$3 > $1".sh"}' gsmd.csv gives me this #!/bin/sh #GETTING FILE scp root@192.168.1.150:/data/monthend/foo/r11/par410p1.ga00 monthend/foo/r11/par410p1.ga00 #PUTTING FILE scp monthend/foo/r11/par410p1.ga00 root@159.142.175.59:r11/ #!/bin/sh #GETTING FILE scp root@192.168.1.150:/data/monthend/gsa/rco/par410p1.ga00 monthend/foo/rco/par410p1.ga00 #PUTTING FILE scp monthend/foo/rco/par410p1.ga00 root@159.142.175.59:rco/par410p1.ga00 and that should work, No? |
Yeah. Good! ;)
|
from what i see, you can just do everything inside one script..there's no need to create another script just contain your scp commands.
|
All times are GMT -5. The time now is 10:27 PM. |