I need a bash script that every day at 4 am verifys the home user directory for the next entrys
- Registers all user action in root/login/checl.log
- Excluds UID inferior then 500 and that home/dev/null
- Create's the the user home directory if it does not exist
- guarantees that the the home directory belongs to the right users
- removes all premissions for users other
- if the files /WWW/index.html does not existe create it
---------- Post updated 15-01-10 at 12:08 AM ---------- Previous update was 14-01-10 at 04:54 PM ----------
Code:
#! /bin/bash
infoUsers=$(cat /etc/passwd | cut -d':' -f1,3,6)
for infoUser in $infoUsers
do
userName=$(echo $infoUser | cut -d':' -f1)
uid=$(echo $infoUser | cut -d':' -f2)
uDir=$(echo $infoUser | cut -d':' -f3)
idGroup=$(cat /etc/passwd | cut -d':' -f4)
if [ '"$uid" -ge "500" && ! $uDir -eq "/dev/null"' ];
then
if [ ! -d $uDir ]
then
$(mkdir $uDir)
fi
$(chown $userName $uDir)
groupName=$(cat /etc/group | grep $idGroup | cut -d':' -f1)
$(chgrp $groupName $uDir)
$(chmod o-rwx $uDir)
if [ ! -f "$uDir/www/index.html" ]
then
$(echo "Welcome!" > "$uDir""/www/index.html")
$(chmod o-w+rx "$uDir""/www/index.html")
fi
fi
done
for file in /root/logins/login*
do
echo "$file" >> "/root/logins/check.log"
cat "$file" >> "/root/logins/check.log"
done
well this is what a got, but when I was going to test it this script bust up my users or something and my linux got **** up. What you think was the problem
Last edited by pludi; 01-15-2010 at 01:57 AM..
Reason: code tags, please...
What happened to your system? Can you describe any effects, or post any output?
Where corrections were applied:
Old code is in red
New code is in Green
Comments are in Blue
Code:
#! /bin/bash
infoUsers=$(cat /etc/passwd | cut -d':' -f1,3,6)# If you want the group, too, then you'll have to get it here, not inside the loopinfoUsers=$(cat /etc/passwd | cut -d':' -f1,3,6,4)
for infoUser in $infoUsers
do
userName=$(echo $infoUser | cut -d':' -f1)
uid=$(echo $infoUser | cut -d':' -f2)
uDir=$(echo $infoUser | cut -d':' -f3)
idGroup=$(cat /etc/passwd | cut -d':' -f4)# See above comment. Better to get the group outside the loop, not insideidGroup=$(echo $infoUser | cut -d':' -f4)if [ '"$uid" -ge "500" && ! $uDir -eq "/dev/null"' ];# As soon as you surround a variable or constant with quotes it becomes a
string, which isn't suitable for testing with -gt/-lt
# Also, you don't have to quote the whole test expressionif [ $uid -ge 500 && ! "$uDir" -eq "/dev/null" ];
then
if [ ! -d $uDir ]
then
$(mkdir $uDir)# No need to capture the output of mkdir here using $()mkdir $uDir
fi
$(chown $userName $uDir)#Again, no need to capturechown $userName $uDir# This is optional. You can change the ownerships by ID just as well
groupName=$(cat /etc/group | grep $idGroup | cut -d':' -f1)
$(chgrp $groupName $uDir)
$(chmod o-rwx $uDir)#Again, no need to capturechgrp $groupName $uDir
chmod o-rwx $uDir
if [ ! -f "$uDir/www/index.html" ]
then
$(echo "Welcome!" > "$uDir""/www/index.html")
$(chmod o-w+rx "$uDir""/www/index.html")
fi
fi
done
for file in /root/logins/login*
do
echo "$file" >> "/root/logins/check.log"
cat "$file" >> "/root/logins/check.log"
done
well my sistem got all the test replaced by xxxxxx and [][][][][][][] then I restarted it but it will not boot now so I installed a new one, i'm running this on a virtual machine. Thanks for every thing
I'm new to utilities like socat and netcat and I'm not clear if they will do what I need.
I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes.
I'm using Cygwin bash on Windows 10.
My... (3 Replies)
Hello all,
I am facing a weird issue while executing a code below -
#!/bin/bash
cd /wload/baot/home/baotasa0/sandboxes_finance/ext_ukba_bde/pset
sh UKBA_publish.sh UKBA 28082015 3
if
then
echo "Param file conversion for all the areas are completed, please check in your home directory"... (2 Replies)
I am trying to call a script(callingscript.sh) from a master script(masterscript.sh) to get string type value from calling script to master script. I have used scripts mentioned below.
#masterscript.sh
./callingscript.sh
echo $fileExist
#callingscript.sh
echo "The script is called"... (2 Replies)
I am using blow script :--
#!/bin/bash
FIND=$(ps -elf | grep "snmp_trap.sh" | grep -v grep) #check snmp_trap.sh is running or not
if
then
# echo "process found"
exit 0;
else
echo "process not found"
exec /home/Ketan_r /snmp_trap.sh 2>&1 & disown -h ... (1 Reply)
Hi guys
I have a shell script that executes sql statemets and sends the output to a file.the script takes in parameters executes sql and sends the result to an output file.
#!/bin/sh
echo " $2 $3 $4 $5 $6 $7
isql -w400 -U$2 -S$5 -P$3 << xxx
use $4
go
print"**Changes to the table... (0 Replies)