How do I make a script and make it executable?Bruce B wrote:
Here is a very simple script that won't seem to work. Please try it.
Scriptname rAfter you've made it executable, run it.Code: Select all
#!/bin/bash cd /
Basic Shell (Console) operation for beginners
I believe you meanIn the meantime chown 755 scriptname will suffice
Code: Select all
chmod 755 scriptname
I did. Thank you very much. I'll edit the original.rcrsn51 wrote:I believe you meanIn the meantime chown 755 scriptname will sufficeCode: Select all
chmod 755 scriptname
This is one reason why the open source model works, peer review.
~
-
- Posts: 94
- Joined: Tue 19 Apr 2011, 11:53
Code: Select all
chmod +x scriptname
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.
These are the relevant lines (thanks DaveS):
I want to substitute both values (5 and 1) by values from a textfile.
I built a textfile named "boot-savefile" with:
From console, I get access to the file with
I made a simple script for testing:
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
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.
These are the relevant lines (thanks DaveS):
Code: Select all
read -t 5 NUMSAVE
[ -z "$NUMSAVE" ] && NUMSAVE=1
I built a textfile named "boot-savefile" with:
Code: Select all
time=10
default=2
Code: Select all
#grep "time=" boot-savefile | cut -f 2 -d '='
10
#grep "default=" boot-savefile | cut -f 2 -d '='
2
#
Code: Select all
TST1=grep "time=" boot-savefile | cut -f 2 -d '='
echo $TST1
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.
Raspberry Pi without Puppy? No, thanks.
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:
changed to:
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
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 ' '`"
Code: Select all
read -t 5 NUMSAVE
[ -z "$NUMSAVE" ] && NUMSAVE=1
[ $NUMSAVE -ne 0 ] && PUPSAVE="`cat /tmp/PUPSAVE2SFSS | tr '\n' ' ' | cut -f $NUMSAVE -d ' '`"
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.
Raspberry Pi without Puppy? No, thanks.
Bruce,
I don't understand:
OK, maybe step by step. Please forget everything before.
I have a textfile named boot-savefile with:
And a script:
gives the expected result: 20. OK.
Typing in console:
gives the expected result: 10
In the script:
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.Works.
Thanks for trying to help.
I don't understand:
Yes, I want help, and for 2 times I tried my very best to explain what I want and where I'm struggling.-n 1 saves from entering the selection then the enter key - just enter the selection
OK, maybe step by step. Please forget everything before.
I have a textfile named boot-savefile with:
Code: Select all
time=10
default=2
Code: Select all
TST1=20
echo $TST1
Typing in console:
Code: Select all
grep "time=" boot-savefile | cut -f 2 -d '='
In the script:
Code: Select all
TST1=grep "time=" boot-savefile | cut -f 2 -d '='
echo $TST1
What is wrong, please?
It seems to be a stupid, basic problem of misunderstanding from me.
Rolf
Edit: OK, I got it.
Code: Select all
TST1=$(grep "time=" boot-savefile | cut -f 2 -d '=')
Thanks for trying to help.
Ich verwende "frugal", und das ist gut so. :wink:
Raspberry Pi without Puppy? No, thanks.
Raspberry Pi without Puppy? No, thanks.
Sorry I wasn't on the same page with you.rhadon wrote:In the script:Code: Select all
TST1=grep "time=" boot-savefile | cut -f 2 -d '='
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
~
Thanks for clarification, Bruce.
I just learned again that it's always good, thinking twice or more before posting.
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 `.
So another mystery is solved for me.
Thanks,
Rolf
I just learned again that it's always good, thinking twice or more before posting.
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 `.
So another mystery is solved for me.
Thanks,
Rolf
Ich verwende "frugal", und das ist gut so. :wink:
Raspberry Pi without Puppy? No, thanks.
Raspberry Pi without Puppy? No, thanks.
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
~
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
~
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.
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
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
#
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
Ich verwende "frugal", und das ist gut so. :wink:
Raspberry Pi without Puppy? No, thanks.
Raspberry Pi without Puppy? No, thanks.
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
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
Rhadon,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 )?
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
~
Ok Bruce,
here is what I have:
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.
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:
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.
Rolf
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
My first thought, if initrd is loading, I have access to PSUBDIR and everything is fine. Nice dream.
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).
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.
Rolf
Ich verwende "frugal", und das ist gut so. :wink:
Raspberry Pi without Puppy? No, thanks.
Raspberry Pi without Puppy? No, thanks.
Hi,
IT WORKS
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 onlyReplace 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.
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.
IT WORKS
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
boot-savefile (in PSUBDIR) contains only
Code: Select all
time=n
default=n
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.
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.
Raspberry Pi without Puppy? No, thanks.