Other Help Topics :: Script help needed please



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

i think this is kinda like what you need (untested):
Code Sample

link_docs() {
DOC_DIR="/mnt/hda5/MyDocuments"
if [ ! -d "$DOC_DIR" ]; then
mkdir -p "$DOC_DIR"
fi
ln -s  "$DOC_DIR"  $HOME/MyDocs
}
mount /dev/hda5 && link_docs

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

Is /mnt/hda5 writeable by the user running the script?  Is the partition mounted successfully?
How about this...
Code Sample

link_docs() {
DOC_DIR="/mnt/hda5/MyDocuments"
if [ -d "$DOC_DIR" ]; then
ln -s  "$DOC_DIR"  $HOME/MyDocuments
else
mkdir -p "$DOC_DIR" && ln -s  "$DOC_DIR"  $HOME/MyDocuments
fi
}
mount /mnt/hda5 && link_docs


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.

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

Next Page...
original here.