<DIV>
<P><FONT face="Courier New, Courier, mono" size=-1>1:#!/bin/bash<BR></FONT></P>
<P><FONT face="Courier New, Courier, mono" size=-1>2:# Merge symlink files<BR>3:# Author: Damien Clark<BR>4:# Date: 8/Oct/2000<BR>5:# Purpose:<BR>6:#<BR>7:# Merge files from multiple directories into one directory by linking<BR>8:# This script will create links to files from all of the filename arguments<BR>9:# provided on commandline into the current directory, or from the filename<BR>10:# arguments provided on stdin if no filenames provided on command line.<BR>11:#<BR>12:# The script will check the following properties of the file, before linking it:<BR>13:#<BR>14:# : make sure that each filename provided is actually a regular file (not a<BR>15:# directory or symlink or device file)<BR>16:# : make sure that each file is readable<BR>17:# : make sure that the effective user running the script owns the file,<BR>18:# or the effective group is the group owner ofthe file<BR>19:#<BR>20:# The script will also work properly on filenames with spaces. For example:<BR>21:#<BR>22:#
 /home/clarkd/My Resume.doc<BR>23:#<BR>24:# Usage: $0 [-s] [-c] [<FILENAME1> <FILENAME2>...]<BR>25:#<BR>26:# -c option -> continue processing even if an error is detected on a file.<BR>27:# Without this option, the script will stop if an error is<BR>28:# detected with a file.<BR>29:#<BR>30:# -s option -> create symbolic links instead of hard links (does not check<BR>31:# if on same filesystem)<BR>32:#<BR>33:# If the script is provided file names as standard input, it can be expressed<BR>34:# as shown in the example below:<BR>35:#<BR>36:# find ~ -type f -print| generatelinks.sh -s<BR>37:#<BR>38:# The command above will create symbolic links to the files found within the<BR>39:# user's home directory, if the file properties match as above.<BR>40:#<BR>41:# If the script is run with filenames provided as command line argument, as<BR>42:# shown in the example below:<BR>43:#<BR>44:# generatelinks.sh /home/clarkd/*.doc /home/clarkd/documents/*.doc<BR>45:#<BR>46:# without the !
-c
 option, then the script will ask to confirm whether to continue<BR>47:# not to continue, or to continue for all.<BR></FONT></P>
<P><FONT face="Courier New, Courier, mono" size=-1>48:#Process each file and link it if it is okay.<BR>49:processfile<BR>50:{<BR>51: lnopts="$1"<BR>52: filename="$2"<BR></FONT></P>
<P><FONT face="Courier New, Courier, mono" size=-1>53: #file must be "normal file"<BR>54: if [ ! -f "$filename" ]<BR>55: then<BR>56: echo Not a normal file: $filename<BR>57: retval=1<BR>58: #must have "read perms"<BR>59: elif [ ! -r "$filename" ]<BR>60: then<BR>61: echo "No read permissions: $filename"<BR>62: retval=1<BR>63: #user must either effective owner the file or effective group owner of the file<BR>64: elif [ ! -O "$filename" -o ! -G "$filename" ]<BR>65: then<BR>66: echo "No effective ownership or effective group ownership of file: $filename"<BR>67: retval=1<BR>68: #Otherwise all is well, link the file to current directory using existing name<BR>69: else<BR>70: ln $lnopts $filename<BR>71: retval=$?<BR>72: fi<BR></FONT></P>
<P><FONT face="Courier New, Courier, mono" size=-1>73: #Return the exit status code > 0 if a problem occured<BR>74: return $retval<BR>75:}<BR></FONT></P>
<P></P>
<P><FONT face="Courier New, Courier, mono" size=-1>76:# Initialise variables<BR>77:cont='N'<BR>78:lnopts=''<BR></FONT></P>
<P><FONT face="Courier New, Courier, mono" size=-1>79:# Process switches<BR>80:while test "$1" = '-c' '-o' "$1" = '-s'<BR>81:do<BR>82: if [ "$1" = '-c' ]<BR>83: then<BR>84: cont='Y'<BR>85: shift<BR>86: fi<BR>87: if [ "$1" = '-s' ]<BR>88: then<BR>89: lnopts='-s'<BR>90: shift<BR>91: fi<BR>92:done<BR></FONT></P>
<P><FONT face="Courier New, Courier, mono" size=-1>93:echo "Commencing generation of files<BR></FONT></P>
<P><FONT face="Courier New, Courier, mono" size=-1>94:if [$# -lt 1]<BR></FONT></P>
<P><FONT face="Courier New, Courier, mono" size=-1>95: while read filename<BR>96: do<BR>97: processfile "$lnopts" "$filename"<BR>98: result=$?<BR></FONT></P>
<P><FONT face="Courier New, Courier, mono" size=-1>99: test $result -ne 0 -a "$cont" != 'Y' -a "$cont" != 'y' || exit 1<BR>100: done<BR></FONT></P>
<P><FONT face="Courier New, Courier, mono" size=-1>101:else<BR></FONT></P>
<P><FONT face="Courier New, Courier, mono" size=-1>102: for filename in $*<BR>103: do<BR>104: processfile "$lnopts" "$filename"<BR>105: result=$?<BR></FONT></P>
<P><FONT face="Courier New, Courier, mono" size=-1>106: if [ $result -ne 0 -a "$cont" != 'Y' ]<BR>107: then<BR>108: echo -n "Error occurred. Continue (y/n/a)? "<BR>109: read $cont<BR></FONT></P>
<P><FONT face="Courier New, Courier, mono" size=-1>110: test "$cont" = 'n' -o "$cont" = 'N' && exit 1<BR>111: [ "$cont" = 'a' || "$cont" = 'A' ] && cont='Y'<BR>112: fi<BR>113: done<BR></FONT></P>
<P><FONT face="Courier New, Courier, mono" size=-1>114:fi<BR></FONT></P>
<P><FONT face="Courier New, Courier, mono" size=-1>115:echo "All files processed"</FONT><FONT face="Courier New, Courier, mono"><BR></FONT></P>
<H3>Hints/Tips</H3>
<P>• There is only one mistake per line.<BR>• ALWAYS include the line number, the description of the problem and your solution.<BR></P></DIV><p>
                <hr size=1>Do you Yahoo!?<br>
<a
href="http://us.rd.yahoo.com/mail_us/taglines/msgr/evt=26088/*http://messenger.yahoo.com">Y! Messenger</a> - Communicate in real time. Download now.