Link to home
Start Free TrialLog in
Avatar of The Rock
The RockFlag for India

asked on

script output not proper using kickstart installation

Hi All,

I am creating a custom iso in which i need to transfer one small script via kickstart.cfg file to /etc/profile in post installation section but it wont copied cleanly:

cat >> /usr/local/bin/script << EOF_script

#!/bin/bash

PROCCOUNT=`ps -l | wc -l`
PROCCOUNT=`expr $PROCCOUNT - 4`
if [[ $(groups) == *irc* ]]; then
ENDPROC=`cat /etc/security/limits.conf | grep "@irc" | grep nproc | awk {'print $4'}`
ENDSESSION=`cat /etc/security/limits.conf | grep "@irc" | grep maxlogins | awk {'print $4'}`
PRIVLAGED="IRC Account"
else
ENDPROC=`cat /etc/security/limits.conf | grep "*" | grep nproc | awk {'print $4'}`
ENDSESSION="Unlimited"
PRIVLAGED="Regular User"
fi

echo -e "

+++++++++++++++++: System Data :+++++++++++++++++++
+ Hostname = `hostname`
+ Address = `/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`
+ Kernel = `uname -r`
+ Server Installation Date = `rpm -qi basesystem | grep Install | cut -c 15-46`
+ Uptime = `uptime | sed 's/.*up ([^,]*), .*/1/'`
+ No of CPU = `grep processor /proc/cpuinfo | wc -l`
+ `lscpu | grep 'socket'`
+ Memory = `cat /proc/meminfo | grep MemTotal | awk {'print $2'}` kB
++++++++++++++++++: User Data :++++++++++++++++++++
+ Username = `whoami`
+ Privlages = $PRIVLAGED
+ Sessions = `who | grep $USER | wc -l` of $ENDSESSION MAX
+ Processes = $PROCCOUNT of $ENDPROC MAX
+++++++++++++++++++++++++++++++++++++++++++++++++++
"

EOF_script

above data should be copied as it is in /etc/profile to run properly but actually it get copied the output of above commands.

kindly help - i tried with echo"" also but same thing happening
Avatar of gelonida
gelonida
Flag of France image

could you just try with a simpler example and then enhance step by step till it breaks?

Two other small questions.
Why do you >> /usr/local/bin/script
this should be
> /usr/local/bin/script

>> appends to an existing script, but if you append, then the line
#!/bin/bash is useless as it works only as the first line of a script.

I'd suggest to try
cat >> /usr/local/bin/script << EOF_script
#!/bin/bash
touch /tmp/afile
EOF_script

Open in new window


make also sure that you have no trailing white spaces in the lines containing 'EOF_script'

Will the file be created?
Avatar of The Rock

ASKER

thanks for your feedback - actually most of the part copied sucessfully but issues is this it copied after the command executed . but i want it to go without execution .i dont want ouput i want same script as it is after kickstart installation
For example

Hostname = `hostname` line copied as Hostname = local.domain which i dont want.

i want it as Hostname = `hostname` only
OK. please look at following script
#!/bin/bash

a=3

echo without quotes
cat << eot
$a b c `date`
eot

echo with single quotes
cat << 'eot'
$a b c `date`
eot

Open in new window


and its output:
without quotes
3 b c Tue, Apr 14, 2015  6:27:28 PM
with single quotes
$a b c `date`

Open in new window


if you don't want  expansion in the << eot, then use quotes
Thank you looks good - i will test it tommorrow and let you know.

I have also post 2 more question for kickstart only - if you get chance please have a look and advice! thanks
Well I hope my answer helps.
Unfortunaely I don't know kickstart, so probably can't help a lot there.
Hi Gelonida - it didnt work - even bad then before - kindly help
Could you post your changed script?
Or perhaps even better:
the shortest possible script that shows the problem?

did you use cat or did you use echo?
Here it is:

cat >> `/usr/local/bin/dynmotd' << EOF_dynmotd


#!/bin/bash

PROCCOUNT=`ps -l | wc -l`
PROCCOUNT=`expr $PROCCOUNT - 4`
if [[ $(groups) == *irc* ]]; then
ENDPROC=`cat /etc/security/limits.conf | grep "@irc" | grep nproc | awk {'print $4'}`
ENDSESSION=`cat /etc/security/limits.conf | grep "@irc" | grep maxlogins | awk {'print $4'}`
PRIVLAGED="IRC Account"
else
ENDPROC=`cat /etc/security/limits.conf | grep "*" | grep nproc | awk {'print $4'}`
ENDSESSION="Unlimited"
PRIVLAGED="Regular User"
fi

echo -e "

+++++++++++++++++: System Data :+++++++++++++++++++
+ Hostname = `hostname`
+ Address = `/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`
+ Kernel = `uname -r`
+ Server Installation Date = `rpm -qi basesystem | grep Install | cut -c 15-46`
+ Uptime = `uptime | sed 's/.*up ([^,]*), .*/1/'`
+ No of CPU = `grep processor /proc/cpuinfo | wc -l`
+ `lscpu | grep 'socket'`
+ Memory = `cat /proc/meminfo | grep MemTotal | awk {'print $2'}` kB
++++++++++++++++++: User Data :++++++++++++++++++++
+ Username = `whoami`
+ Privlages = $PRIVLAGED
+ Sessions = `who | grep $USER | wc -l` of $ENDSESSION MAX
+ Processes = $PROCCOUNT of $ENDPROC MAX
+++++++++++++++++++++++++++++++++++++++++++++++++++
"

EOF_dynmotd

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of gelonida
gelonida
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you it works fine .nice one