Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sat 02 Aug 2014, 05:08
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Some questions re a rather complicated script
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [6 Posts]  
Author Message
scsijon

Joined: 23 May 2007
Posts: 1026
Location: the australian mallee

PostPosted: Tue 13 Nov 2012, 07:27    Post subject:  Some questions re a rather complicated script
Subject description: 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> Question


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
View user's profile Send private message Visit poster's website 
L18L

Joined: 19 Jun 2010
Posts: 2505
Location: Burghaslach, Germany somewhere also known as "Hosla"

PostPosted: Tue 13 Nov 2012, 09:55    Post subject: Re: Some questions re a rather complicated script
Subject description: 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
View user's profile Send private message 
seaside

Joined: 11 Apr 2007
Posts: 886

PostPosted: 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
View user's profile Send private message 
scsijon

Joined: 23 May 2007
Posts: 1026
Location: the australian mallee

PostPosted: 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! Laughing
Back to top
View user's profile Send private message Visit poster's website 
L18L

Joined: 19 Jun 2010
Posts: 2505
Location: Burghaslach, Germany somewhere also known as "Hosla"

PostPosted: 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! Laughing

A very simple script could result from a description of what you really want in simple plain English. Smile
Sorry, but I did not get want you want.
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4293

PostPosted: 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 .....

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [6 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0650s ][ Queries: 12 (0.0050s) ][ GZIP on ]