-
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

Lenovo - Yoga 7i 2-in-1 16" 2K Touchscreen Laptop - Intel Core Ultra 5 Proces...
$749.99

Lenovo ThinkPad T14 G2 14-Inch AMD Ryzen R5 5650U 16GB, 512GB SSD Win 11 Pro
$398.99

Lenovo ThinkPad L15 Gen 3 15.6" 16GB, Thunder Black
$241.50

Lenovo ThinkPad T14 Gen 2 14" i7-1165G7 2.80GHz 16GB RAM 512GB SSD Windows 11
$284.99

LENOVO THINKPAD P15S GEN 2i CORE I7-1185G7 2.8GHZ 32GB 512GB NVIDIA T500 W11
$300.00

LENOVO THINKPAD T14 GEN 2i CORE I7-11165G7 2.8GHZ 16GB 256 SSD WCAM WI1 CORD
$235.00

Lenovo ThinkPad T14 Gen 2 i5-1145G7 16GB 512GB SSD Touch Win 11 Pro Good
$261.99

Lenovo - IdeaPad Slim 3 15.6" Full HD Laptop - AMD Ryzen 5 40 2025 - 8GB Memo...
$379.99

Lenovo ThinkPad L15 Gen 3 15.6" 16GB, Thunder Black
$241.50

Lenovo ThinkPad T14 Gen 2 14" Touchscreen i7-1185G7 16GB RAM 512GB SSD Win 11
$284.99