Script help needed pleaseForum: Other Help Topics Topic: Script help needed please started by: clivesay Posted by clivesay on Dec. 28 2004,16:02
I need some script help if possible. For my NFP machines I am going to run frugal with a MyDocuments symlink to another partition for file storage. This will keep files from being loaded into RAM. Currently I have a simple command in bootlocal.sh that mounts the partition and creates a symbolic link to to a MyDocuments folder on the hda5 partition. Since I am doing many installs I want to automate as much as possible, what I really need are commands in bootlocal similar to the following...... mount hda5 and check to see if there is a MyDocuments folder, if there is then just create the symlink to /home/dsl. If there is not a MyDocuments folder on hda5 then create one and then create the symlink. I have done some very simple bash scripting but I am clueless when it comes to if/then statements. Can someone help me with this one? Thanks Chris Posted by mikshaw on Dec. 28 2004,17:03
i think this is kinda like what you need (untested):
Posted by clivesay on Dec. 28 2004,17:16
Thank you, mikshaw. I will give this a try.Edit: It appears that it creates a MyDocs link in /home/dsl but there is nothing in /hda5. Ideally there would be a /MyDocuments folder on /dev/hda5 and a /MyDocuments link in /home/dsl Chris Posted by mikshaw on Dec. 28 2004,19:41
Is /mnt/hda5 writeable by the user running the script? Is the partition mounted successfully?How about this...
This one will attempt to create the directory on /mnt/hda5 if it doesn't exist, and if mkdir is successful it will link. If the mkdir command fails the link will not be created. NOTE: I've noticed that 'if' tests sometimes work differently with DSL than they do on my workstation. I think my 'if' is a Tcl built-in command and DSL's might be part of a different package. I'll check it out in a few minutes. Posted by clivesay on Dec. 28 2004,20:22
mikshaw -Thank you so much that seems to do what I want! That will save me some setup time. Thanks again. I'll continue to test. Chris Posted by mikshaw on Dec. 28 2004,20:27
ok...well I wrote a different one in the meantime. This was tested on an unmodified DSL 0.9.1:
The difference is basically that the link name is automatically generated depending on the name of the target directory, and it exits if the mount fails. It still doesn't account for failure to write to the target partition. Posted by clivesay on Dec. 28 2004,20:33
I just tested your second script at boot and it appears that it is not creating the link if MyDocuments already exists on hda5. I want it create the link if it finds /mnt/hda5/MyDocuments.The idea is that the first time I boot after doing a frugal install, it sees there is not a MyDocuments folder on hda5 so it creates one and then links it. On every boot after that, I just want it to create the link to the now existing /mnt/hda5/MyDocuments dir. I hope this makes sense Chris Posted by mikshaw on Dec. 28 2004,20:37
Alright...I made a slight modification. If the directory doesn't exist it is created. The ln command is run either way. My syntax was wrong....i thought it would link either way, but I guess not.
Posted by clivesay on Dec. 28 2004,20:56
mikshaw -We are getting close. It appears the third script ran OK but it placed the symlink in the root dir instead of /home/dsl Chris Posted by mikshaw on Dec. 28 2004,21:54
well that's weird.... "$HOME/`basename $DOCDIR`" should be /home/dsl/MyDocuments. It's not really necessary to do that...I just thought it would be easier in case you wanted to change the directory. Until I get back to it you could change the last line toln -s "$DOCDIR" /home/dsl/MyDocuments or use the other script. by the way, is it "MyDocuments" or "My Documents"? A space in there might screw things up. Posted by clacker on Dec. 28 2004,22:05
mikshaw, Your Bash skill never fail to wow me. I'd swear I get something new out of every example. I really liked the use of variables to hold the parts, so that it would be easy to change things.I think the reason that the script was putting things into /root instead of /home/dsl was because if you are running the script as user root $HOME=/root whereas running it as user dsl $HOME=/home/dsl Posted by clivesay on Dec. 28 2004,22:18
adding the full path worked just fine. Thanks alot for your help. I'll do some test installs this evening.I have you noted in the code. Chris Posted by mikshaw on Dec. 29 2004,05:55
ok then, I wasn't aware that you were running it as root. Instead of "$HOME/`basename $DOCDIR`" it could be "/home/dsl/`basename $DOCDIR`". When you said that the symlink was put in the root directory I thought you meant '/' when you actually meant '/root'. That makes sense.Variables, in my opinion, are the most useful element in scripting. Not only do they allow you to easily modify set values in scripts, but they are also used a lot when you need to get a value which may vary depending on the environment, hence the name 'variable'. I had my first taste of them doing actionscript in Flash 4. After doing several projects with Flash3 (no variables) and making everything linear and specific, the introduction of variables opened up a whole new world of user interaction. |