Sponsored Content
Top Forums Shell Programming and Scripting Determine if variable is the Server component of UNC Post 302881500 by Festus Hagen on Monday 30th of December 2013 01:13:33 AM
Old 12-30-2013
Determine if variable is the Server component of UNC

Hi all,

Using sh/csh, unfortunately shell scripts are not my strong suit.

Trying to write a script that gets called from a program for pre-processing.
The program passes individual components of a UNC (//server/path1/path2/filename).

Thus the unc path of: //server/path1/path2/filename, is 4 calls to myscript with each call having a single parameter of:
//server
//server/path1
//server/path1/path2
//server/path1/path2/filename

I need to be able to determine if the current component is the Server component or not. ie: //server not //server/blah.

Figured that would be easy ... Something simple like:
Code:
RESULT=`echo "$1" | sed -e '/^\/\/.+\//p'`
if [ ! "$RESULT" ]; then
  echo "Server Component"
else
  echo "Path components"
fi

should get it done, Obviously I was wrong.

How can I go about this or what am I doing wrong?

The Server component will always begin with two slashes followed by a name, no trailing slash.
Non server components will always have two leading slashes, the server name followed by a slash ... and more.
If it does not start with two leading slashes it should be completely ignored.

Thanks

-Enjoy
fh : )_~
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using Perl to connect UNC Filepaths on Domain

I'm trying to use Perl on Windows (Doh!) to connect to a folder on a Domain Controller via UNC. Right now, I have perl -e "`runas /user:DOMAIN\\Username dir \\\\SERVER\\d\$\\Path`" This does not seem to connect nor does it prompt for password. Should I try throwing it into a script and... (0 Replies)
Discussion started by: adelsin
0 Replies

2. IP Networking

How to Determine client's DNS server Ip

Is there a way for a server to determine client's DNS ip? I have an application that logs client's IP but in certain cases its desirable to know their DNS too (1 Reply)
Discussion started by: vickylife
1 Replies

3. Shell Programming and Scripting

To verify status of particular Component(Siebel Server srvrmgr)

Hi , I want to connect srver to pertuculat mode(i.e.srvrmanger)and after that I want to verify status of perticular component(i.e.CommOutboundMgr) For that I have created following script bout after 3rd line it is not executing 4th linei.e. list comp CommOutboundMgr. cd... (2 Replies)
Discussion started by: vivek1489
2 Replies

4. Shell Programming and Scripting

Parse file name out of UNC path

Hello, I searched the forums and didn't see a situation like this: I cannot figure out how to parse out just the file name from the full path. The path looks like this: \\foo\bar\filename.ext I don't think something like 'cut' will work so I tried to whip up a regex but couldn't get it... (12 Replies)
Discussion started by: bytesnoop
12 Replies

5. Shell Programming and Scripting

Determine a shell variable exists in file?

Hi Folks, Trying to build up a script that will lookup a username invoked as: ./buildscript.sh <username> This should take <username> and look it up in <username_file> and prepare for further processing. Here is the snippet that isn't working just right: user=$1 if ]; then echo... (1 Reply)
Discussion started by: gdenton
1 Replies

6. Shell Programming and Scripting

To determine the File Sytem Usage on Multiple UNIX server

Hello All :) I want to write a shell script to find the file system usage on multiple UNIX servers. Commands: df -g fsJCAPS Below script works fine and it displays results on terminal/console. I want to store /redirect output on to local server from where I'm running the script. ... (3 Replies)
Discussion started by: Mohammad Nawaz
3 Replies

7. Red Hat

How to determine share name of Linux server?

Hi, How to determine share name of Linux server ? OS version is RHL 6.5 Regards, Maddy (11 Replies)
Discussion started by: Maddy123
11 Replies

8. Web Development

Script to determine which web server at ip addresses

how do we determine if ip addresses are hosting IIS version 7.x or Apache 2.2.x. ? (3 Replies)
Discussion started by: NameSake
3 Replies

9. Shell Programming and Scripting

Script to determine server IP

Need help with the script, I am trying to include this script as part of kickstart profile. based of the host's IP address, in this case if the host is IP starting with 10.10.3.* or 10.10.6.*, I will be pushing appropriate routing file from my web server. I validate host IP from nslookup. ... (3 Replies)
Discussion started by: bobby320
3 Replies
EXCHANGEDATA(2) 					      BSD System Calls Manual						   EXCHANGEDATA(2)

NAME
exchangedata -- atomically exchange data between two files SYNOPSIS
#include <unistd.h> #include <sys/attr.h> int exchangedata(const char * path1, const char * path2, unsigned int options); DESCRIPTION
The exchangedata() function swaps the contents of the files referenced by path1 and path2 in an atomic fashion. That is, all concurrent pro- cesses will either see the pre-exchanged state or the post-exchanged state; they can never see the files in an inconsistent state. The data in all forks is swapped in this way. The options parameter lets you control specific aspects of the function's behaviour. Open file descriptors follow the swapped data. Thus, a descriptor that previously referenced path1 will now reference the data that's acces- sible via path2, and vice versa. In general, the file attributes (metadata) are not exchanged. Specifically, the object identifier attributes (that is, the ATTR_CMN_OBJID and ATTR_CMN_OBJPERMANENTID attributes as defined by the getattrlist(2) function) are not swapped. An exception to this general rule is that the modification time attribute ( ATTR_CMN_MODTIME ) is swapped. When combined, these features allow you to implement a 'safe save' function that does not break references to the file (for example, aliases). You first save the new contents to a temporary file and then exchange the data of the original file and the temporary. Programs that reference the file via an object identifier will continue to reference the original file, but now it has the new data. The path1 and path2 parameters must both reference valid files. All directories listed in the path names leading to these files must be searchable. You must have write access to the files. The options parameter is a bit set that controls the behaviour of exchangedata(). The following option bits are defined. FSOPT_NOFOLLOW If this bit is set, exchangedata() will not follow a symlink if it occurs as the last component of path1 or path2. RETURN VALUES
Upon successful completion a value of 0 is returned. Otherwise, a value of -1 is returned and errno is set to indicate the error. COMPATIBILITY
Not all volumes support exchangedata(). You can test whether a volume supports exchangedata() by using getattrlist(2) to get the volume capabilities attribute ATTR_VOL_CAPABILITIES, and then testing the VOL_CAP_INT_EXCHANGEDATA flag. ERRORS
exchangedata() will fail if: [ENOTSUP] The volume does not support exchangedata(). [ENOTDIR] A component of the path prefix is not a directory. [ENAMETOOLONG] A component of a path name exceeded NAME_MAX characters, or an entire path name exceeded PATH_MAX characters. [ENOENT] Either file does not exist. [EACCES] Search permission is denied for a component of the path prefix. [ELOOP] Too many symbolic links were encountered in translating the pathname. [EFAULT] path1 or path2 points to an invalid address. [EXDEV] path1 and path2 are on different volumes (mounted file systems). [EINVAL] path1 or path2 reference the same file. [EINVAL] You try to exchange something other than a regular file (for example, a directory). [EIO] An I/O error occurred while reading from or writing to the file system. SEE ALSO
getattrlist(2), rename(2) HISTORY
A exchangedata() function call appeared in Darwin 1.3.1 (Mac OS X version 10.0). It was deprecated in macOS 10.13. Darwin December 15, 2003 Darwin
All times are GMT -4. The time now is 05:04 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy