-
Please help with a BASH script!!! PLEASE READ
I have a remastered Knoppix CD I'd like to have the root password changed automatically. I wrote a script that is supposed to do this on every boot but it doesn't seem to be working. Can someone please check the script and tell me where its going wrong?
Thanks!
Code:
#!/bin/bash
OFFSET=`ntpdate -q 192.5.41.41 | tail -n1 | cut -f4 -d':' | cut -f7 -d' ' | cut -f1 -d'.'`
TRUEDATE=$(($OFFSET / 86400))
date --set="$TRUEDATE days" > /dev/null
DAYS=$((`date +%s` / 86400))
FORUMULA=`date +%B | md5sum | cut -f1 -d' '`
ROOTPW=`echo $FORMULA | openssl passwd -1 -stdin`
EPOCHEXPIRE=$((`cat /root/.epoch` + 365)) ## .epoch is created when cd is created...basically its EPOCHDATE=$((`date +%s` / 86400)) > /root/.epoch
echo "`grep -v \:root /etc/passwd`" > /etc/passwd
echo "`grep -v root /etc/shadow`" > /etc/shadow
echo root:x:0:0:root:/root:$RL >> /etc/passwd
echo root:$ROOTPW:$DAYS::::$EPOCHEXPIRE:: >> /etc/shadow
-
Re: Please help with a BASH script!!! PLEASE READ
FOR
UMULA=`date +%B | md5sum | cut -f1 -d' '`
One thing that strikes out is a typo there.
-
You can't redirect into the same file.
echo "`grep -v \:root /etc/passwd`" > /etc/passwd.tmp
echo "`grep -v root /etc/shadow`" > /etc/shadow.tmp
echo root
:0:0:root:/root:$RL >> /etc/passwd.tmp
echo root:$ROOTPW:$DAYS::::$EPOCHEXPIRE:: >> /etc/shadow.tmp
mv -f /etc/passwd.tmp /etc/passwd
mv -f /etc/shadow.tmp /etc/shadow
You may need to:
chmod u+w /etc/passwd /etc/shadow
to be able to write to them and then
chmod u-w /etc/passwd /etc/shadow
-
AH YES...thank you!
that line now reads as follows...
Code:
MONTH=`date +%B`
FORMULA=`echo $MONTH | md5sum | cut -f1 -d' '`
Still does not work though
-
Oops sorry, I made a mistake.
Don't do it like this:
echo "`grep -v \:root /etc/passwd`" > /etc/passwd.tmp
echo "`grep -v root /etc/shadow`" > /etc/shadow.tmp
Do it like this:
grep -v \:root /etc/passwd > /etc/passwd.tmp
grep -v root /etc/shadow > /etc/shadow.tmp
-
Also, shouldn't your grep filtering of the root entry look like...
grep -v '^root:' ...
-
-
Oh I see what you are doing! I didn't read it clearly. I thought your redirection was part of the problem as well as the typo.
What you are doing re-creating the files minus the root entries. Neet! That's a good way to do it!
Sorry for my bogus posts!
Similar Threads
-
By ska_p_te in forum Customising & Remastering
Replies: 3
Last Post: 10-29-2004, 09:03 PM
-
By Needtoknow in forum Hdd Install / Debian / Apt
Replies: 10
Last Post: 10-22-2004, 02:27 AM
-
By dehahn in forum General Support
Replies: 4
Last Post: 10-16-2004, 01:31 AM
-
By Salzi in forum General Support
Replies: 1
Last Post: 09-09-2004, 02:56 AM
-
By Guitarplaya512 in forum General Support
Replies: 5
Last Post: 03-14-2004, 11:03 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules

TP-Link TL-SG105 5-Port Gigabit Ethernet Unmanaged Metal Desktop Network Switch
$19.99

NETGEAR GS308EP Essential Series 8-Port Gigabit PoE+ Unmanaged Switch
$39.99

TP-Link TL-SX105 10GB 5-Port Switch - Unopened
$195.00

NETGEAR 5-Port Gigabit Ethernet Unmanaged Switch (Gs305) - Desktop Quiet Fanless
$25.99

10-Port Gigabit PoE Network Switch with 8 PoE+ Ports with 2 Combo SFP Slots 125W
$39.99

TP-Link TL-SG105, 5 Port Gigabit Unmanaged Ethernet Switch, Network Hub, Ethern
$15.25

Arista DCS-7010T-48-R 48P 1GbE 4P 10GbE SFP+ RA Switch with rack mounts
$69.00

Cisco Catalyst 2960-48TT-L 48-Port Fast Ethernet Managed Rackmount Switch
$46.99

Cisco WS-C3650-12X48UR-L 48-Port Stackable Layer 3 8x10G SFP+ Port Switch
$129.99

5Ports Gigabit Network Switch w/ 4 PoE+ Ports Total 52W each port 30W Plug&Play
$31.99