Results 1 to 8 of 8

Thread: Please help with a BASH script!!! PLEASE READ

  1. #1
    Member registered user
    Join Date
    Sep 2004
    Posts
    34

    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

  2. #2
    Senior Member
    Join Date
    Nov 2003
    Posts
    1,323

    Re: Please help with a BASH script!!! PLEASE READ

    FORUMULA=`date +%B | md5sum | cut -f1 -d' '`
    One thing that strikes out is a typo there.

  3. #3
    Junior Member
    Join Date
    Oct 2004
    Posts
    4
    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

  4. #4
    Member registered user
    Join Date
    Sep 2004
    Posts
    34
    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

  5. #5
    Junior Member
    Join Date
    Oct 2004
    Posts
    4
    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

  6. #6
    Junior Member
    Join Date
    Oct 2004
    Posts
    4
    Also, shouldn't your grep filtering of the root entry look like...

    grep -v '^root:' ...

  7. #7
    Member registered user
    Join Date
    Sep 2004
    Posts
    34
    in editing the script again i found the problem...basically a typo!...FORMULA is mispelled if you read below...causing a blank pw everytime...

    smxsteve...

    have you tried the commands? it works...and works nicely... as for the grep -v '^root:' ...
    since on my knoppix cd there is another account that has /root as its home i have to separate that from this one...

    Markus...

    thank you!!! you found it! i was just looking in the wrong spot for typo...

    here is my current working portion of my aioscript that changes the admin password at boot time...just make sure you keep the formula a secret...

    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)) 
    FORMULA=`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
    If you guys want to know what is my aioscript i have a thread in the ms windows section about it

    thank you for your input...i knew it was something simple

  8. #8
    Junior Member
    Join Date
    Oct 2004
    Posts
    4
    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

  1. Adding a bash script to you starting up list
    By ska_p_te in forum Customising & Remastering
    Replies: 3
    Last Post: 10-29-2004, 09:03 PM
  2. Change OS read only file to read/write after "poor man'
    By Needtoknow in forum Hdd Install / Debian / Apt
    Replies: 10
    Last Post: 10-22-2004, 02:27 AM
  3. C++ Compiler in Bash
    By dehahn in forum General Support
    Replies: 4
    Last Post: 10-16-2004, 01:31 AM
  4. Logging off from bash
    By Salzi in forum General Support
    Replies: 1
    Last Post: 09-09-2004, 02:56 AM
  5. Using Bash
    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
  •  


GIGABYTE A520M DS3H AC AMD AM4 Motherboard mATX picture

GIGABYTE A520M DS3H AC AMD AM4 Motherboard mATX

$59.99



Intel H310 LGA1151 8-9th Gen DDR4 M.2 NVMe mATX Motherboard IO Shield Battery picture

Intel H310 LGA1151 8-9th Gen DDR4 M.2 NVMe mATX Motherboard IO Shield Battery

$54.99



MSI PRO Z790-P WIFI DDR4 LGA 1700 Intel Z790 SATA 6Gb/s DDR4 ATX Motherboard picture

MSI PRO Z790-P WIFI DDR4 LGA 1700 Intel Z790 SATA 6Gb/s DDR4 ATX Motherboard

$163.49



ASUS PRIME Z490-P LGA 1200 Intel Z490 SATA 6Gb/s ATX Intel Motherboard NEW picture

ASUS PRIME Z490-P LGA 1200 Intel Z490 SATA 6Gb/s ATX Intel Motherboard NEW

$121.45



GIGABYTE B365 HD3 LGA1151 Intel 9th Gen motherboard picture

GIGABYTE B365 HD3 LGA1151 Intel 9th Gen motherboard

$59.99



ASRock B550M PRO4 AM4 AMD B550 SATA 6Gb/s Micro ATX AMD Motherboard picture

ASRock B550M PRO4 AM4 AMD B550 SATA 6Gb/s Micro ATX AMD Motherboard

$76.49



⁠Intel H81 Motherboard M.2 NVMe LGA 1150 mATX w/ IO Shield (Random Slot Color)⁠ picture

⁠Intel H81 Motherboard M.2 NVMe LGA 1150 mATX w/ IO Shield (Random Slot Color)⁠

$29.90



ASUS H110I-PLUS Motherboard LGA1151 w/ I5-7400 CPU, 8GB, Heatsink & I/O Shield picture

ASUS H110I-PLUS Motherboard LGA1151 w/ I5-7400 CPU, 8GB, Heatsink & I/O Shield

$60.00



MSI B460m-Bomber LGA 1200 Intel 10th Gen B460 M-ATX Intel Motherboard picture

MSI B460m-Bomber LGA 1200 Intel 10th Gen B460 M-ATX Intel Motherboard

$59.99



ASUS B85M-G/B85M-G PLUS LGA1150 DDR3 Micro ATX Motherboard HDMI for Inter 4thCPU picture

ASUS B85M-G/B85M-G PLUS LGA1150 DDR3 Micro ATX Motherboard HDMI for Inter 4thCPU

$45.00