Deploy ksh script to file from other script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Deploy ksh script to file from other script
# 1  
Old 07-20-2012
Deploy ksh script to file from other script

Hi all,

I need to deploy two scripts on around ~100 machines and have only OPSware.
Opsware have the option to execute a script, so I am trying to write a script which dose

Code:
cat > script.ksh <<EOF
script to be deployed
EOF

However the script between the two EOFs gets also executed which is a problem.
I have also tried with perl

Code:
open FILE,">script.ksh" or die "Write error";
print FILE <<EOF
script to be deployed
EOF

but some parts of the script are still processed.

Here is my code


Code:
#!/bin/bash

cat > script.ksh <<EOF
#!/usr/bin/ksh
# Where to save the current rules
IPT_FILE="/var/log/iptables.state"
# Send mail to whom
MAIL="root"
# Should we override the recorded IPT_FILE
# every time a change is detected(this will prevent duplicate messages
OVERRIDE="yes"
 
# Path to iptables - leave it so if you are not sure
IPTABLES=$(which iptables)
 
### CONFIGURATION ENDS HERE
 
check()
{
cmp -s <($IPTABLES -L -n) $IPT_FILE
if [ $? -ne 0 ]
 then
    echo -e "Iptables change detected \n Current iptables rules        Previous iptables rules \n \n `diff -y <($IPTABLES -L -n) $IPT_FILE`" | mail -s "Iptables rules changed on $(hostname -f)" $MAIL
     if [ $OVERRIDE == "yes" ]
      then
      $IPTABLES -L -n > $IPT_FILE
      chmod 600 $IPT_FILE
     fi
    exit 1;
 else
    exit 0;
fi
}
 
initial()
{
 
if [[ -s $IPT_FILE ]]
 then
   check
 else
   $IPTABLES -L -n > $IPT_FILE
   chmod 600 $IPT_FILE
   check
fi
}
 
initial
EOF


Output and debug


Quote:
root@debian-test:~# bash -x ./upload.sh
+ cat
++ which iptables
++ diff -y /dev/fd/63
diff: missing operand after `/dev/fd/63'
diff: Try `diff --help' for more information.
+++ -L -n
++ hostname -f
./upload.sh: line 3: -L: command not found
root@debian-test:~# ./upload.sh
diff: missing operand after `/dev/fd/63'
diff: Try `diff --help' for more information.
./upload.sh: line 3: -L: command not found
root@debian-test:~#

Any help is greatly appreciated!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh Script, Reading A File, Grepping A File Contents In Another File

So I'm stumped. First... APOLOGIES... my work is offline in an office that has zero internet connectivity, as required by our client. If need be, I could print out my script attempts and retype them here. But on the off chance... here goes. I have a text file (file_source) of terms, each line... (3 Replies)
Discussion started by: Brusimm
3 Replies

2. Shell Programming and Scripting

ksh script trying to pass a variable to edit a file

I'm trying to create a ksh script that will ask the user for the port number. $PORT1 is the variable I want to use that will contain whatever numbers the user inputs. The script would edit ports.txt file, search and delete "./serv 110.1.0.1.$PORT1 200;=3" . So if the user types 50243 then the... (5 Replies)
Discussion started by: seekryts15
5 Replies

3. Shell Programming and Scripting

ksh script to edit a file using vi editor

I was wondering if it is possible to execute a script that will remove a certain search pattern from a file and save it? Manually I would just hit escape to enter command mode then search and delete the pattern "./srv 135.0.0.1.11111 210;=1" then save & exit the file vi command to search and... (3 Replies)
Discussion started by: seekryts15
3 Replies

4. Ubuntu

How to lock a file through UNIX KSH shell script?

I wrote two shell scripts in UNIX that renames the same file and scheduled them at the same time. The following are the steps that I followed:- 1. I wrote 2 scripts named s1.sh and s2.sh, both trying to add “exec_” prefix to the name of the files present in a folder i which already don't start... (4 Replies)
Discussion started by: piuli
4 Replies

5. UNIX for Dummies Questions & Answers

File Inbound/Outbound shell script(ksh)

URGENT ---------- Post updated at 04:26 AM ---------- Previous update was at 04:23 AM ---------- (I could not post I didn't know why so I need to put the contents via reply, sorry) Hi all :D, I am a newbie of Unix shell script and I was assigned the work from user that I need to... (3 Replies)
Discussion started by: gogkub
3 Replies

6. Shell Programming and Scripting

KSH script for split a txt file

I have a problem which I would like to solve by using UNIX power and inspired minds around world. Here is the problem I have a text file and it has data as follows 1X.....................1234567890123456789T1234598765XT1 (header) 1Z01............(sub HEADER) P100001............ Q1........... (4 Replies)
Discussion started by: ask.chowhan
4 Replies

7. Shell Programming and Scripting

KSH - help needed for creating a script to generate xml file from text file

Dear Members, I have a table in Oracle DB and one of its column name is INFO which has data in text format which we need to fetch in a script and create an xml file of a new table from the input. The contents of a single cell of INFO column is like: Area:app - aam Clean Up Criteria:... (0 Replies)
Discussion started by: Yoodit
0 Replies

8. Shell Programming and Scripting

KSH script to run other ksh scripts and output it to a file and/or email

Hi I am new to this Scripting process and would like to know How can i write a ksh script that will call other ksh scripts and write the output to a file and/or email. For example ------- Script ABC ------- a.ksh b.ksh c.ksh I need to call all three scripts execute them and... (2 Replies)
Discussion started by: pacifican
2 Replies

9. Shell Programming and Scripting

How to get timestamp of file into ksh script

Hi - I need to run a script via cron which will do some ldapsearches. One of the search parameters will be modifytimestamp. I need to have some way of storing the timestamp of the last time the script ran, and then retrieving that timestamp to use in the ldapsearch command (i.e.... (5 Replies)
Discussion started by: sniper57
5 Replies

10. Shell Programming and Scripting

import var and function from ksh script to another ksh script

Ih all, i have multiples ksh scripts for crontab's unix jobs they all have same variables declarations and some similar functions i would have a only single script file to declare my variables, like: var1= "aaa" var2= "bbb" var3= "ccc" ... function ab { ...} function bc { ... }... (2 Replies)
Discussion started by: wolfhurt
2 Replies
Login or Register to Ask a Question