LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Server harding shell script for RHEL 5.0 (https://www.linuxquestions.org/questions/linux-server-73/server-harding-shell-script-for-rhel-5-0-a-4175452006/)

imtiyaj 02-27-2013 10:47 PM

Server harding shell script for RHEL 5.0
 
Dear All,
Following shell script is working on Centos, RHEL 4.0 but it won't work on RHEL 5.0.
let explain
Command chkconfig ntpd off work as single command but it create shell script and this command in shell script it won't work.
Kindly suggest what step we want to take to run shell script on RHEL 5.0 ( permission 777, .sh,etc)
chkconfig is not working in shell script
---------------------------------------------------------------------
#!/bin/bash
chkconfig autofs off
chkconfig avahi-daemon off
chkconfig avahi-dnsconfd off
chkconfig bluetooth off
chkconfig conman off
chkconfig cups off
chkconfig dhcdbd off
chkconfig firstboot off
chkconfig gpm off
chkconfig haldaemon off
chkconfig isdn off
chkconfig iptables off
chkconfig ip6tables off
chkconfig irda off
chkconfig irqbalance off
chkconfig kdump off
chkconfig kudzu off
chkconfig mcstrans off
chkconfig microcode_ctl off
chkconfig multipathd off
chkconfig netconsole off
chkconfig netfs off
chkconfig netplugd off
chkconfig nfs off
chkconfig nfslock off
chkconfig nscd off
chkconfig pcscd off
chkconfig portmap off
chkconfig rdisc off
chkconfig rhnsd off
chkconfig restorecond off
chkconfig rpcgssd off
chkconfig rpcidmapd off
chkconfig rpcsvcgssd off
chkconfig sendmail off
chkconfig smartd off
chkconfig winbind off
chkconfig wpa_supplicant off
chkconfig xfs off
chkconfig ypbind off
chkconfig yum-updatesd off
chkconfig acpid on
chkconfig anacron on
chkconfig atd on
chkconfig cpuspeed on
chkconfig lvm2-monitor on
chkconfig messagebus on
chkconfig ntpd on
chkconfig network on
chkconfig oracle on
chkconfig oracleasm on
chkconfig readahead_early on
chkconfig readahead_later on
chkconfig syslog on
chkconfig sshd on
------------------------------------------------------------

fortran 02-28-2013 01:39 AM

What is the error when you run the shell script?
When you run the chkconfig on terminal (without shell script), does it run fine?

imtiyaj 02-28-2013 03:38 AM

Error when executing script
 
Following error encounter after shell script run on server.
and direct command is run properly.


usage: chkconfig --list [name]
chkconfig --add <name>
chkconfig --del <name>
chkconfig [--level <levels>] <name> <on|off|reset|resetpriorities>
chkconfig version 1.3.30.1 - Copyright (C) 1997-2000 Red Hat, Inc.
This may be freely redistributed under the terms of the GNU Public License.

usage: chkconfig --list [name]
chkconfig --add <name>
chkconfig --del <name>
chkconfig [--level <levels>] <name> <on|off|reset|resetpriorities>
chkconfig version 1.3.30.1 - Copyright (C) 1997-2000 Red Hat, Inc.
This may be freely redistributed under the terms of the GNU Public License.

usage: chkconfig --list [name]
chkconfig --add <name>
chkconfig --del <name>
chkconfig [--level <levels>] <name> <on|off|reset|resetpriorities>
chkconfig version 1.3.30.1 - Copyright (C) 1997-2000 Red Hat, Inc.
This may be freely redistributed under the terms of the GNU Public License.

usage: chkconfig --list [name]
chkconfig --add <name>
chkconfig --del <name>
chkconfig [--level <levels>] <name> <on|off|reset|resetpriorities>
chkconfig version 1.3.30.1 - Copyright (C) 1997-2000 Red Hat, Inc.
This may be freely redistributed under the terms of the GNU Public License.

usage: chkconfig --list [name]
chkconfig --add <name>
chkconfig --del <name>
chkconfig [--level <levels>] <name> <on|off|reset|resetpriorities>
chkconfig version 1.3.30.1 - Copyright (C) 1997-2000 Red Hat, Inc.
This may be freely redistributed under the terms of the GNU Public License.

usage: chkconfig --list [name]
chkconfig --add <name>
chkconfig --del <name>
chkconfig [--level <levels>] <name> <on|off|reset|resetpriorities>
chkconfig version 1.3.30.1 - Copyright (C) 1997-2000 Red Hat, Inc.
This may be freely redistributed under the terms of the GNU Public License.

usage: chkconfig --list [name]
chkconfig --add <name>
chkconfig --del <name>
chkconfig [--level <levels>] <name> <on|off|reset|resetpriorities>
chkconfig version 1.3.30.1 - Copyright (C) 1997-2000 Red Hat, Inc.
This may be freely redistributed under the terms of the GNU Public License.

usage: chkconfig --list [name]
chkconfig --add <name>
chkconfig --del <name>
chkconfig [--level <levels>] <name> <on|off|reset|resetpriorities>

fortran 02-28-2013 05:09 AM

Add following lines after
#!/bin/bash
Code:

#chkconfig: 2345 95 20
# description: Description of the script
# processname:test

The first line, even if commented, is used by chkconfig and must be present defines that on runlevels 2,3,4 and 5, this subsystem will be activated with priority 95 (one of the lasts), and deactivated with priority 20 (one of the firsts).

I was facing almost similar problem but my error was different.
I used sudo before chkconfig in shell script and it was working fine.
To test the old script, I tried to run it in Korn Shell and it was working there but it was not working in BASH.
But your error is different, I don't know it would work for you.

imtiyaj 02-28-2013 06:12 AM

Thank you -- I will confirm same
 
Dear Sir,

It is not working similar error message on same

unSpawn 02-28-2013 06:39 AM

Well it clearly says you should "chkconfig --level 12345 $SERVICENAME off". Also note this isn't a "hardening" script in any way plus RHEL 5U0 is way outdated, they're at U9 for some time now.

imtiyaj 02-28-2013 10:03 PM

Thank you -- I will confirm same
 
Thank you for good information

chrism01 02-28-2013 10:27 PM

Actually, --level is optional; it defaults to the current set levels.
Have you by chance copied this script via an MS system; maybe its a line ending issue?

As above, 5.0 is way out of date. Unless you absolutely have to have this version, use the latest 5.9 (or even 6.4).

On 6.3 (Centos) it defaults to levels 2345
Code:

chkconfig --list|grep ntp
ntpd                  0:off        1:off        2:on        3:on        4:on        5:on        6:off
ntpdate                0:off        1:off        2:off        3:off        4:off        5:off        6:off

 chkconfig ntpd off
 chkconfig --list|grep ntp
ntpd                  0:off        1:off        2:off        3:off        4:off        5:off        6:off
ntpdate                0:off        1:off        2:off        3:off        4:off        5:off        6:off

 chkconfig ntpd on
 chkconfig --list|grep ntp
ntpd                  0:off        1:off        2:on        3:on        4:on        5:on        6:off
ntpdate                0:off        1:off        2:off        3:off        4:off        5:off        6:off



All times are GMT -5. The time now is 06:14 AM.