Basic Shell (Console) operation for beginners

Booting, installing, newbie
Message
Author
eriksatie
Posts: 41
Joined: Tue 07 Jun 2011, 03:27

#286 Post by eriksatie »

Bruce B wrote:
Here is a very simple script that won't seem to work. Please try it.

Scriptname r

Code: Select all

#!/bin/bash
cd /
After you've made it executable, run it.
How do I make a script and make it executable?

Bruce B

#287 Post by Bruce B »

eriksatie wrote:How do I make a script and make it executable?
I guess that wasn't mentioned. I'll come back and make a thorough reply.

In the meantime chmod 755 scriptname will suffice

~
Last edited by Bruce B on Thu 09 Jun 2011, 02:13, edited 1 time in total.

User avatar
rcrsn51
Posts: 13096
Joined: Tue 05 Sep 2006, 13:50
Location: Stratford, Ontario

#288 Post by rcrsn51 »

In the meantime chown 755 scriptname will suffice
I believe you mean

Code: Select all

chmod 755 scriptname

Bruce B

#289 Post by Bruce B »

rcrsn51 wrote:
In the meantime chown 755 scriptname will suffice
I believe you mean

Code: Select all

chmod 755 scriptname
I did. Thank you very much. I'll edit the original.

This is one reason why the open source model works, peer review.

~

SimpleWater
Posts: 94
Joined: Tue 19 Apr 2011, 11:53

#290 Post by SimpleWater »

Code: Select all

chmod +x scriptname
that works fine for me, also easier to remember than numbers and fewer characters too

User avatar
rhadon
Posts: 1292
Joined: Thu 27 Mar 2008, 11:05
Location: Germany

#291 Post by rhadon »

Hi,

inspired by this thread, I tried to solve it by my own.
btw. I think this feature could be worth to be integrated in all new puppies. :wink:

These are the relevant lines (thanks DaveS):

Code: Select all

read -t 5 NUMSAVE 
 [ -z "$NUMSAVE" ] && NUMSAVE=1
I want to substitute both values (5 and 1) by values from a textfile.

I built a textfile named "boot-savefile" with:

Code: Select all

time=10
default=2
From console, I get access to the file with

Code: Select all

#grep "time=" boot-savefile | cut -f 2 -d '='
10
#grep "default=" boot-savefile | cut -f 2 -d '='
2
#
I made a simple script for testing:

Code: Select all

TST1=grep "time=" boot-savefile | cut -f 2 -d '='
echo $TST1
I tried now for 2 days, several hours a day, to get this working. No chance. No matter what I tried, and I really tried a lot.

Maybe I don't see the trees for the wood. Where am I wrong?

Thanks
Rolf
Ich verwende "frugal", und das ist gut so. :wink:
Raspberry Pi without Puppy? No, thanks.

Bruce B

#292 Post by Bruce B »

Rolf,

Please post the names save files on your list in order from top to bottom.

Please tell me if there is a default, such as the one at the top.

Please zip init if you are not using Lupu 5.20

Bruce

~

If you don't know how to open initrd.gz tell me

User avatar
rhadon
Posts: 1292
Joined: Thu 27 Mar 2008, 11:05
Location: Germany

#293 Post by rhadon »

Bruce,

the code from DaveS works fine. I can change the time or the default savefile. But every time I want to change something, like I want another savefile by default, I have to edit the initrd.gz. I know how to do but it's annoying. It is much easier to edit a simple textfile. That's the actual reason for me, digging in bash programming.

I now use Lupu 5.25 and I think it's equal to 5.20
the original part of init ~line 782:

Code: Select all

     read NUMSAVE
    [ $NUMSAVE -ne 0 ] && PUPSAVE="`cat /tmp/PUPSAVE2SFSS | tr '\n' ' ' | cut -f $NUMSAVE -d ' '`"
changed to:

Code: Select all

read -t 5 NUMSAVE 
  [ -z "$NUMSAVE" ] && NUMSAVE=1
    [ $NUMSAVE -ne 0 ] && PUPSAVE="`cat /tmp/PUPSAVE2SFSS | tr '\n' ' ' | cut -f $NUMSAVE -d ' '`"
As I wrote, it works fine but with values from a external textfile it would be great.

For now my savefiles are: lupusave.3fs, lupusave-compile.3fs and lupusave-dummy.3fs. I don't think, it is important.

Rolf
Last edited by rhadon on Thu 23 Jun 2011, 05:48, edited 1 time in total.
Ich verwende "frugal", und das ist gut so. :wink:
Raspberry Pi without Puppy? No, thanks.

Bruce B

#294 Post by Bruce B »

Rolf,

I thought you wanted help. I'll offer a suggesiton that made it more enjoyable for me

-n 1 saves from entering the selection then the enter key - just enter the selection

try it

Bruce

~

User avatar
rhadon
Posts: 1292
Joined: Thu 27 Mar 2008, 11:05
Location: Germany

#295 Post by rhadon »

Bruce,

I don't understand:
-n 1 saves from entering the selection then the enter key - just enter the selection
Yes, I want help, and for 2 times I tried my very best to explain what I want and where I'm struggling.

OK, maybe step by step. Please forget everything before.

I have a textfile named boot-savefile with:

Code: Select all

time=10 
default=2
And a script:

Code: Select all

TST1=20
echo $TST1
gives the expected result: 20. OK.

Typing in console:

Code: Select all

grep "time=" boot-savefile | cut -f 2 -d '='
gives the expected result: 10

In the script:

Code: Select all

TST1=grep "time=" boot-savefile | cut -f 2 -d '='
echo $TST1
doesn't work. Also everthing I tried to get it work, failed.

What is wrong, please?

It seems to be a stupid, basic problem of misunderstanding from me.

Rolf

Edit: OK, I got it. :D

Code: Select all

TST1=$(grep "time=" boot-savefile | cut -f 2 -d '=')
Works.

Thanks for trying to help.
Ich verwende "frugal", und das ist gut so. :wink:
Raspberry Pi without Puppy? No, thanks.

Bruce B

#296 Post by Bruce B »

rhadon wrote:In the script:

Code: Select all

TST1=grep "time=" boot-savefile | cut -f 2 -d '='
Sorry I wasn't on the same page with you.

I'll offer a tip for the future when setting variables such as the one above.


Commonly we use backtics
Compare first line, which won't work, with the second, which will work

TST1=grep "time=" boot-savefile | cut -f 2 -d '='
TST1=`grep "time=" boot-savefile | cut -f 2 -d '='`

I can't define what the backtics do in every scenario, but in this case, I explain it is saying; move the results of my commands from right to left into the variable.

Bruce

~

User avatar
rhadon
Posts: 1292
Joined: Thu 27 Mar 2008, 11:05
Location: Germany

#297 Post by rhadon »

Thanks for clarification, Bruce.

I just learned again that it's always good, thinking twice or more before posting. :lol:

Just before telling you that I tried backtics several times and it doesn't work, I realised that I always used normal tics (I hope that's the right term), as ' instead of `. :oops:

So another mystery is solved for me.

Thanks,

Rolf
Ich verwende "frugal", und das ist gut so. :wink:
Raspberry Pi without Puppy? No, thanks.

Bruce B

#298 Post by Bruce B »

Quotes and apostrophes work also and are frequently used when setting variables. The key is to know what they do.

Here is something for you to copy and paste to your console if you want to see the effects. One command at a time from top to bottom.

myvar='echo $PATH'

$myvar

myvar="echo $PATH"

$myvar

myvar=`echo $PATH | cut -d : -f 1-3`

$myvar

unset myvar


~

User avatar
rhadon
Posts: 1292
Joined: Thu 27 Mar 2008, 11:05
Location: Germany

#299 Post by rhadon »

Thanks again, I got it.

I was playing with the cut command for better understanding. So I changed the delimiter to /.

Now there's a difference between running this command directly or moving the result of the command into myvar and then asking the value of myvar.

Code: Select all

# echo $PATH | cut -d / -f 1-5
/bin:/usr/bin:/sbin:

# myvar=`echo $PATH | cut -d / -f 1-5`
# $myvar
bash: /bin:/usr/bin:/sbin:: No such file or directory
# 

Shouldn't both kinds give identical results? OK, the result is equal, but why no comment above?


Another question. I've built a small script which seems to work fine. But adding it to the init script of initrd doesn't work. I think I know why, but not how to solve. For now I will try to find it out by myself. A new day, new ideas ...and so on.

If I can't solve this for me, is it OK to post such questions here (maybe initrd isn't so interesting for others here) or should I post in a separate thread, maybe in Users ( For the regulars )?

Rolf

Edit: Aaarrrggg... I hate typos but typos love me. edited the third time :oops:
Ich verwende "frugal", und das ist gut so. :wink:
Raspberry Pi without Puppy? No, thanks.

User avatar
01micko
Posts: 8741
Joined: Sat 11 Oct 2008, 13:39
Location: qld
Contact:

#300 Post by 01micko »

Hi Rolf

I saw this before dinner but I thought I'll let it go for a little while..

echo "$myvar"

It works without the double quotes too.

Cheers
Puppy Linux Blog - contact me for access

User avatar
rhadon
Posts: 1292
Joined: Thu 27 Mar 2008, 11:05
Location: Germany

#301 Post by rhadon »

Thanks Mick,

got it. Nice to see you here.

Rolf
Ich verwende "frugal", und das ist gut so. :wink:
Raspberry Pi without Puppy? No, thanks.

Bruce B

#302 Post by Bruce B »

rhadon wrote:If I can't solve this for me, is it OK to post such questions here (maybe initrd isn't so interesting for others here) or should I post in a separate thread, maybe in Users ( For the regulars )?
Rhadon,

This is why I think couldn't follow. I did what you apparently want to do, and I used a different approach.

I you want to work on this together, please specify exactly what you want and we'll give it a try. But patience, it could take a few days between breaks and all.

Bruce

~

User avatar
rhadon
Posts: 1292
Joined: Thu 27 Mar 2008, 11:05
Location: Germany

#303 Post by rhadon »

Ok Bruce,

here is what I have:

Code: Select all

#!/bin/sh
PSUBDIR="/lupu-525"		#given by init script
ONEPART="sda2"			#given by init script

ls /mnt/home/$PSUBDIR/boot-savefile>/dev/null
if [ "$?" = "0" ] 
then
	TST1=`grep "time=" /mnt/home/$PSUBDIR/boot-savefile | cut -f 2 -d '='`
	TST2=`grep "default=" /mnt/home/$PSUBDIR/boot-savefile | cut -f 2 -d '='`
	echo "Savefile #" $TST2 "will start automatically in " $TST1 "seconds." # in init script >/dev/console must be added
   read -t $TST1 NUMSAVE 
	[ -z "$NUMSAVE" ] && NUMSAVE=$TST2	
else
	read NUMSAVE			# this is the original place during boot where to select the savefile, ~ line#782 in init script
fi
echo "NUMSAVE="$NUMSAVE		# for testing
This works fine as a stand alone script. It fails in init script.. OK, it is clear, that /mnt/home/ doesn't work.

My first thought, if initrd is loading, I have access to PSUBDIR and everything is fine. Nice dream. :lol:

At this point of the init script it seems to me that nothing is mounted.
#mount gives nothing back. With #ls I can see that I'm in the init-tree.

My idea was/is to mount $ONEPART (here sda2), searching for boot-savefile in $PSUBDIR and to umount it later.
The way I know, #mount /dev/$ONEPART /mnt/$ONEPART doesn't work.

In the README.txt I find:

Code: Select all

/initrd/pup_rw
This is the writable folder. Usually it is tmpfs (temporary filesystem) in ram.
However, a personal storage file (named "pup_save.2fs" or similar) or partition 
could be mounted directly on here (in which case it won't be on /initrd/pup_ro1).
So this seems to be the right place to mount sda2 temporarily. But how? All commands in ini about mounting are looking so complicated, I don't understand.

At ~line 176 there's a function called mntfunc(). I assume, most mounting will be done with this function. It seems to check for different file systems. Maybe a better solution than trying myself?

For now I think I must at least specify more, like file system (here ext3) .

What do you think? Is it a workable way?

Opinions from others are also appreciated. :wink:

Rolf
Ich verwende "frugal", und das ist gut so. :wink:
Raspberry Pi without Puppy? No, thanks.

User avatar
rhadon
Posts: 1292
Joined: Thu 27 Mar 2008, 11:05
Location: Germany

#304 Post by rhadon »

Hi,

IT WORKS :D :D :lol:

Code: Select all

    TST3=`echo $PUPSFS | cut -d , -f 2`
	mntfunc $TST3 /dev/$PDEV1 /mnt/dev_ro2 
	ls /mnt/dev_ro2$PSUBDIR/boot-savefile >/dev/null
	if [ "$?" = "0" ] 
	then
		TST1=$(grep "time=" /mnt/dev_ro2$PSUBDIR/boot-savefile | cut -f 2 -d '=')
		TST2=$(grep "default=" /mnt/dev_ro2$PSUBDIR/boot-savefile | cut -f 2 -d '=')
		echo "If no input +[ENTER], savefile #" $TST2 "will start automatically in " $TST1 "seconds." >dev/console
		umntfunc /mnt/dev_ro2
		read -t $TST1 NUMSAVE 
		[ -z "$NUMSAVE" ] && NUMSAVE=$TST2
	else
		umntfunc /mnt/dev_ro2
		echo "To start automatically you can use a textfile named boot-savefile" >/dev/console
		echo "with time=n and default=n in PSUBDIR" >/dev/console
		read NUMSAVE 
	fi
If you replace the original line read NUMSAVE in the init script (in Lupu-525 it's line #782) with the complete code above, you should be able to use a textfile named boot-save to boot automatically one of your savefiles or pfix=ram.

boot-savefile (in PSUBDIR) contains only

Code: Select all

time=n 
default=n
Replace n with your desired values.

It works for frugal installs on HD and with PSUBDIR.
I don't think it works from CD or without using a subdirectory (now).

I like to hear, what I could do better. :wink:

Rolf

Edit:
Just tested a little bit more, it seems to work also fine with Icepuppy-013 and Spup-120.50 but not (now) with Puppy 4.31 or Puppy 4.20. The boot-savefile will not be detected.
Last edited by rhadon on Sat 25 Jun 2011, 17:33, edited 1 time in total.
Ich verwende "frugal", und das ist gut so. :wink:
Raspberry Pi without Puppy? No, thanks.

User avatar
DaveS
Posts: 3685
Joined: Thu 09 Oct 2008, 16:01
Location: UK

#305 Post by DaveS »

Replace read NUMSAVE with read boot-save?
Spup Frugal HD and USB
Root forever!

Post Reply