| Author |
Message |
scsijon
Joined: 23 May 2007 Posts: 948 Location: the australian mallee
|
Posted: Tue 13 Nov 2012, 07:27 Post_subject:
Some questions re a rather complicated script Sub_title: my script starting skills are lousy! |
|
Hi, I need a scriptor or two to give me some code hints for a couple of "somewhat complicated" scripts.
I'll give a warning that I can't write a script for nuts, but can usually work out what one does (unless your talking things like
cut -f 1-8 -d '|'`, and cut -f 10-13 -d '|'`, and sed -e 's%^,%%' | tr ',' '\n' | sort -u | tr '\n' ',' | sed -e 's%,$%%', where you loose me as soon as you start!).
thanks
scsijon
What I need to start with is create a script or two to do these functions>
| Code: |
#!/bin/sh
#script1
# I NEED TO CHECK IF A "FILE" IS A LINK OR NOT
# if /opt/packagenamedirectory/fileorlinkname ISNOT a LINK
# OR IF IT IS AN XML FILE
# then if /opt/packagenamedirectory/fileorlinkname ISNOT a XMLFILE
# OR IF IT'S NOT A TEXT FILE
# then if /opt/packagenamedirectory/fileorlink ISNOT a TEXTFILE
# then "GIVE_A_SCREEN_ERROR_SPLASH" with /opt/packagenamedirectory/fileorlink
# AND the SCRIPT_NAME
# AND await close of splash screen before continuing
# IF IT'S A TEXT FILE IT SHOULDN'T BE IT SHOULD BE A LINK SO FIX IT
# else delete /opt/packagenamedirectory/fileorlink
# AND ln -s /opt/packagenamedirectory2/filename /opt/packagenamedirectory/linkname
# fi
# fi
# IF IT IS A XML FILE IT MAY NEED WORK
# else goto script3
# fi
# IF IT'S A LINK CHECK IT'S THE RIGHT ONE
# else goto script2
# fi
|
| Code: |
#!/bin/sh
#script2
# if /opt/packagenamedirectory/fileorlinkname ISNOT_LINKED_TO /opt/packagenamedirectory2/a_particular_linkname
# then DELETE /opt/packagenamedirectory/fileorlinkname
# AND ln -s /opt/packagenamedirectory2/filename /opt/packagenamedirectory/linkname
# if /opt/packagenamedirectory/fileorlinkname ISNOT_LINKED_TO /opt/packagenamedirectory2/a_particular_linkname
# then DELETE /opt/packagenamedirectory/fileorlinkname
# AND ln -s /opt/packagenamedirectory2/filename /opt/packagenamedirectory/linkname
# if /opt/packagenamedirectory/fileorlinkname ISNOT_LINKED_TO /opt/packagenamedirectory2/a_particular_linkname
# then DELETE /opt/packagenamedirectory/fileorlinkname
# AND ln -s /opt/packagenamedirectory2/filename /opt/packagenamedirectory/linkname
# if /opt/packagenamedirectory/fileorlinkname ISNOT_LINKED_TO /opt/packagenamedirectory2/a_particular_linkname
# then DELETE /opt/packagenamedirectory/fileorlinkname
# AND ln -s /opt/packagenamedirectory2/filename /opt/packagenamedirectory/linkname
# fi
# fi
# fi
# fi
|
| Code: |
#!/bin/sh
#script3
# this script will contain a number of additions/changes to the xml filesets
# it is not yet worked out what will be in each of them!
# if_the_filename_is/opt/packagenamedirectory/xmlfilename1
# then goto DO_THESE_CHANGES1
# if_the_filename_is/opt/packagenamedirectory/xmlfilename2
# then DO_THESE_CHANGES2
# if_the_filename_is/opt/packagenamedirectory/xmlfilename3
# then DO_THESE_CHANGES3
# if_the_filename_is/opt/packagenamedirectory/xmlfilename4
# then DO_THESE_CHANGES4
# if_the_filename_is/opt/packagenamedirectory/xmlfilename5
# then DO_THESE_CHANGES5
# none or a mixed number of changes may be needed
# fi
# fi
# fi
# fi
# fi
#
# DO_THESE_CHANGES1
# the changes??
# return
#
# DO_THESE_CHANGES2
# the changes??
# return
#
# DO_THESE_CHANGES3
# the changes??
# return
#
# DO_THESE_CHANGES4
# the changes??
# return
#
# DO_THESE_CHANGES5
# the changes??
# return
|
|
|
Back to top
|
|
 |
L18L
Joined: 19 Jun 2010 Posts: 1800 Location: Burghaslach, Germany
|
Posted: Tue 13 Nov 2012, 09:55 Post_subject:
Re: Some questions re a rather complicated script Sub_title: my script starting skills are lousy! |
|
| Code: | #!/bin/sh
f=/opt/packagenamedirectory/fileorlinkname
if [ "`file $f | grep ' link '`" ]; then
echo "CHECK IT'S THE RIGHT ONE "
else
echo "Hope that helps"
fi |
You want to do something with an xml file that is not a link or what?
Hope I have not lost you because grep was not in your list.
|
|
Back to top
|
|
 |
seaside
Joined: 11 Apr 2007 Posts: 841
|
Posted: Tue 13 Nov 2012, 11:59 Post_subject:
|
|
scsijon,
| Code: | if [ -L FILENAME ] # if FILENAME is a link
readlink FILENAME # what filename is FILENAME linked to
file FILENAME # what type/kind of file (binary,text,etc) |
Bad news- using the command "file" might require some grep/cut action. If it's just the extension you want, you can do this | Code: | | ext="${FILENAME##*.}" |
Cheers,
s
|
|
Back to top
|
|
 |
scsijon
Joined: 23 May 2007 Posts: 948 Location: the australian mallee
|
Posted: Wed 14 Nov 2012, 02:44 Post_subject:
|
|
thanks folks but what I wrote was an explanation of what I wanted to do not script, no code is implied at this stage!
|
|
Back to top
|
|
 |
L18L
Joined: 19 Jun 2010 Posts: 1800 Location: Burghaslach, Germany
|
Posted: Wed 14 Nov 2012, 06:57 Post_subject:
|
|
| scsijon wrote: | thanks folks but what I wrote was an explanation of what I wanted to do not script, no code is implied at this stage!  |
A very simple script could result from a description of what you really want in simple plain English.
Sorry, but I did not get want you want.
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3845
|
Posted: Wed 14 Nov 2012, 15:55 Post_subject:
|
|
you definitely want to learn "case"
| Code: | case "$FILENAME" in
*.xml)xml_func "$FILENAME";;
/root/*)root_files_func "$FILENAME";;
*doc*)doc_func "$FILENAME";;
*)default_file_func "$FILENAME";;
esac |
this can be used on the results of file
FILERES=$(file ... file_name)
case "$FILERES" in .....
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
|