Sponsored Content
Top Forums Shell Programming and Scripting How to figure out a if insensitive file path exists or not? Post 303041651 by mohtashims on Saturday 30th of November 2019 02:52:56 PM
Old 11-30-2019
Quote:
Originally Posted by Scrutinizer
Ah so it is the other way around? The hostname is always lowercase, but the path may be uppercase?

Try something like:
Code:
cd $(ls -d "$(hostname)"* "$(hostname | tr '[[:lower:]]' '[[:upper:]]')"* 2>/dev/null)

The path and the hostname both may be either upper or lower and we are not certain of that

In such a case how will my ls command to the file still work whether a lower or upper case is encountered ?

--- Post updated at 04:31 PM ---

Quote:
Originally Posted by Scrutinizer
Ah so it is the other way around? The hostname is always lowercase, but the path may be uppercase?

Try something like:
Code:
cd $(ls -d "$(hostname)"* "$(hostname | tr '[[:lower:]]' '[[:upper:]]')"* 2>/dev/null)

Will back-ticks work instead of "$(" ?

--- Post updated at 04:52 PM ---

Quote:
Originally Posted by Scrutinizer
Ah so it is the other way around? The hostname is always lowercase, but the path may be uppercase?

Try something like:
Code:
cd $(ls -d "$(hostname)"* "$(hostname | tr '[[:lower:]]' '[[:upper:]]')"* 2>/dev/null)

Works !! Thank you Scrutinizer for precise answer !!
 

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to check if all directories of file's path exists?

I wonder if the script below is possible to write somehow more efficiently. It seems to me the problem is very common.. CreateFolders() # parameter: name of file with relative path with regard to directory $project_root { echo $1 | awk '{ n=split($1, array, "/"); ... (2 Replies)
Discussion started by: MartyIX
2 Replies

2. Shell Programming and Scripting

color a figure in text file

Good morning, Can someone help to color a figure in columns if its exceeding a threshold using shell script . ex. I have file contains 5 columns showing a value in % I need to show the value in red if it exceed 90 % Appreciate your help (3 Replies)
Discussion started by: Bluetoot
3 Replies

3. Programming

C - How to sheck if a path exists?

How do i check if a path exists in C? (5 Replies)
Discussion started by: omega666
5 Replies

4. Shell Programming and Scripting

File exists, but cannot be opened.How to check- whether it could be opened to read when it exists

Hi #Testing for file existence if ; then echo 'SCHOOL data is available for processing' else echo 'SCHOOL DATA IS NOT AVAILABLE FOR PROCESSING' : i wrote a script, where it begins by checking if file exists or not. If it exists, it truncates the database... (2 Replies)
Discussion started by: rxg
2 Replies

5. Shell Programming and Scripting

Help with change significant figure to normal figure command

Hi, Below is my input file: Long list of significant figure 1.757E-4 7.51E-3 5.634E-5 . . . Desired output file: 0.0001757 0.00751 0.00005634 . . . (10 Replies)
Discussion started by: perl_beginner
10 Replies

6. Shell Programming and Scripting

Case insensitive file name search and replace

I am trying to find case insensitive file names and then replace that particular file with other name. if then ls | grep -i "update" | xargs -I {} mv {} LineItems.csv echo "File moved from *update*" elif then ls | grep -i "priority" | xargs -I {} mv {} ... (1 Reply)
Discussion started by: ATWC
1 Replies

7. UNIX for Beginners Questions & Answers

Convert Relative path to Absolute path, without changing directory to the file location.

Hello, I am creating a file with all the source folders included in my git branch, when i grep for the used source, i found source included as relative path instead of absolute path, how can convert relative path to absolute path without changing directory to that folder and using readlink -f ? ... (4 Replies)
Discussion started by: Sekhar419
4 Replies

8. Programming

Makefile missing include path Although the path exists and defined

i have make file which i try to make them generic but it keeps to compline it missing include directory this is the makefile : CXX=g++ CPPFAGS= -Wall -O0 -g -std=c++14 INCLUDES = -I/home/vagrant/libuv/include -Isrc LIBS_DIRS = -L/home/vagrant/libuv/build LDFLAGS=... (7 Replies)
Discussion started by: umen
7 Replies
STARTPROC(8)						       The SuSE boot concept						      STARTPROC(8)

NAME
Startproc - Start processes identified by path name Start_daemon - Start processes identified by path name SYNOPSIS
startproc [-fLves] [[-n ]+/-<prio>] [-(t|T) <sec>] [-u user] [-g group] [-l log_file|-q|-d] [-p pid_file] [-i ignore_file] [-c root] [-(w|W <file list>)] /path/to/executable [arguments for executable] start_daemon [-fLve] [-n +/-<prio>] [-u user] [-g group] [-l log_file|-q|-d] [-p pid_file] [-i ignore_file] [-c root] /path/to/executable [arguments for executable] SYNOPSIS LSB 3.1 start_daemon [-f] [-n +/-<prio>] /path/to/executable [arguments for executable] DESCRIPTION
startproc and the LSB variant start_daemon check for all processes of the specified executable and starts it if no processes are found. Note that startproc is designed to start a daemon but not a kernel thread or a program which enables a kernel thread. Without any option startproc does search for a process by using the full path of the corresponding program and a default pid file (/var/run/<basename>.pid) which are used together to identify the executable out from the /proc file system (see proc(5)). Only if the inode number (/proc/<pid>/exe) and the full name are unavailable (/proc/<pid>/cmdline) or if the executable changes its zeroth argument, startproc uses the base name (/proc/<pid>/stat) to identify the running program. Extended functionality is provided by the -p option (former option -f changed due to the LSB specification). If this option is specified, startproc tries to check against the pid read from this file instead of the default pid file (/var/run/<basename>.pid). The pid read from this file is compared against the pids of possible running processes that use the specified executable. In order to avoid confusion with stale pid files, a not up-to-date pid will be ignored. For the possibility of having two different sessions of one binary program, the option -i ignore_file allows to specify a pid file which pid number is used to ignore all processes of corresponding process session. The option -v makes startproc print out verbose diagnostics. The start_daemon does not support the options -(t|T) <sec> nor -(w|W <file list>) for waiting for success and the option -s for a new ses- sion as this variant does not fork to start the executable. REQUIRED
/path/to/executable Specifies the executable by its full path name. This argument is always required. Everything that follows this path is considered options for the executable to be launched. Further information can be obtained from the respective manpage(s). OPTIONS
[-n ]+/-<prio> Set the nice level for the process. If used, this option should always be the first in the command line. The nice level <prio> may be specified in the range between -20 and +20. Only root is allowed to set negative nice values. -e Bequeath only a minimal set of environment variables to the new process: HOME, PATH, SHELL, RUNLEVEL, and PREVLEVEL. -p pid_file (Former option -f changed due to the LSB specification.) Use an alternate pid file instead of the default (/var/run/<base- name>.pid). The pid read from this file is being matched against the pid of running processes that have an executable with speci- fied path. In order to avoid confusion with stale pid files, a not up-to-date pid will be ignored. Obviously this option does not work if option -f is specified. -i ignore_file The pid found in this file is used as session id of the same binary program which should be ignored by startproc. Obviously this option does not work if option -f is specified. -f This option is required by the Linux Standard Base Specification (LSB). With this option the start of a process is forced. -g group Sets the group ID of the process to gid. -l log_file Redirect the process standard output and standard error to the file log_file. -L This option causes symlinks to be followed, as the like-named option in ls(1). BR Note : for the file name the original name of the program is used instead of the name of the symbolic link. -c root Change root directory to root. Services which have been started with this option can only be checked by checkproc(8) and signaled by killproc(8) if checkproc(8) and killproc(8) are called with the same option argument for the option -c. -q Equals to -l /dev/null (supresses output). -d Let startproc expect that the started service will do a dialog by prompting for, e.g. a passphrase. This option implies a timeout of 15 seconds (-t 15). -s Starts the process in a new session. The new task is a process group leader and has no controlling tty. -t <sec> The number of seconds to wait after the successful start of a service. This options accepts the number of seconds to wait. You can specify some units after a given number: s for seconds, m for minutes, and h for hours to wait. -T <sec> The same as for option -t but wait only on the started process not on childs forked by the process. -w Wait the first started process to terminate before returning. If the parent process of the daemon does not finish also startproc(8) does not finish. -W <file list> Wait on the provided file or list of files separated with colons. If the files will not be created startproc(8) does not finish. -u user Sets the user ID of the process to user. -v Verbose output. EXAMPLE
startproc /usr/sbin/sendmail starts /usr/sbin/sendmail if no sendmail process is found. If a pid file sendmail.pid exists in /var/run/, then the pid found in this file is used to search the process table for a process with an executable that matches the specified pathname, /usr/sbin/send- mail. If no matching process is found, /usr/sbin/sendmail is launched. startproc -p /var/myrun/lpd.pid /usr/sbin/lpd starts /usr/sbin/lpd if there is no process with the pid found in /var/myrun/lpd.pid and no process in the actual process table exists that uses the specified binary. EXIT CODES
The exit codes have the following LSB conform conditions: 0 Success 1 Generic or unspecified error 2 Invalid or excess argument(s) 4 Insufficient privilege(s) 5 Program is not installed 7 Program is not running In some error cases, diagnostic output is sent to standard error, or, if standard error is not available, syslogd(8) is being used. NOTE
startproc is a replacement for the Bourne shell function daemon found in the widely used SysVinit package of Miquel van Smoorenburg, <miquels@cistron.nl>. startproc is not useful to start kernel threads. This should be done by service utilities designed for the purpose to accomplish this task. BUGS
Identifying a process based on the executable file and the corresponding inode number only works if the process stays alive during start- proc's execution. Processes rewriting their zeroth argument or shell scripts (the inode number of the shell executable file is not identi- cal to that of the script file) may not be identified by a filename path. Startproc does not start a process if there already exists one being in the zombie state. Zombies are processes which arn't alive but listed in the process table to have the exit status ready for the corresponding parent processes. Therefore the parent processes should be check out. Start_daemon is not able to check for exit status of an executable daemon because after the final execve(3) the start_daemon as an own process does not exit anymore. FILES
/proc/ path to the proc file system (see proc(5)). /etc/init.d/ path to the SuSE boot concept script base directory as required by the Linux Standard Base Specification (LSB) (see init.d(7)). SEE ALSO
checkproc(8), killproc(8), insserv(8), init.d(7), kill(1), skill(1), killall(8), killall5(8), signal(7), proc(5). COPYRIGHT
1994-2007 Werner Fink, 1996-2000 SuSE GmbH Nuernberg, Germany. 2007 SuSE LINUX Products GmbH, Nuernberg, Germany. AUTHOR
Werner Fink <werner@suse.de> 3rd Berkeley Distribution Nov 30, 2007 STARTPROC(8)
All times are GMT -4. The time now is 07:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy