Sponsored Content
Top Forums Shell Programming and Scripting Assistance with my Find command to identify last part of a file name and report the name found Post 303041232 by apmcd47 on Tuesday 19th of November 2019 04:20:31 AM
Old 11-19-2019
Quote:
Originally Posted by greavette
Thank you apmcd47 for your helpful reply. I've managed to get the following code working to identify what I need:

Code:
[ -f /var/chef/cache/cookbooks/bootstrap_cookbooks_version_* ] && echo /var/chef/cache/cookbooks/bootstrap_cookbooks_version_* | sed 's/.*version_//'

But what could I add to this code to report that no file was found if a bootstrap_cookbooks_version_* file does not exist?

Thank you.
If you use my second example you could just add a second echo thus:
Code:
f=$(echo/var/chef/cache/cookbooks/bootstrap_cookbooks_version_*) && [ -f "$f" ] && echo ${f##*_} || echo "file does not exist"

In this case the string file does not exist is printed instead of the word red or green. Alternatively look into turning that echo into the instruction you actually want:
Code:
f=$(echo/var/chef/cache/cookbooks/bootstrap_cookbooks_version_*) && [ -f "$f" ] && cat > my_file_is_${f##*_}.txt <<EOT
this will go into the file my_file_is_red.txt
or the file my_file_is_green.txt
only if the file bootstrap_cookbooks_version_red 
(or ..._green) exist!
EOT

Andrew
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with find command and list in a long format each found file

The purpose of those comands are to find the newest file in a directory acvrdind to system date, and it has to be recursively found in each directory. The problem is that i want to list in a long format every found file, but the commands i use produce unexpected results ,so the output lists in a... (5 Replies)
Discussion started by: alexcol
5 Replies

2. Shell Programming and Scripting

find command in while loop - how to get control when no files found?

I have the following statement in script: find ${LANDING_FILE_DIR}${BTIME_FILENAME_PATTERN2} -print | while read file; do ... done When there are no files located by the find comand it returns: "find: bad status-- /home/rnitcher/test/....." to the command line How do I get control in... (3 Replies)
Discussion started by: mavsman
3 Replies

3. Shell Programming and Scripting

print as well as count the files found by find command

I want the output of the find command to be printed and also the total files found by it. Can someone help in this. Obviously $ find . -type f | wc -l will not output the files found but only the count. I want both. There can be millions and trillions of files so dont want the output of find... (3 Replies)
Discussion started by: amicon007
3 Replies

4. UNIX for Dummies Questions & Answers

File not found using find

Hi, i'm currently writing a script which tidys up old files. When using the find command I found that some files were not being listed /export/home/ops***/test: ls -l processed total 0 -rw-rw-r-- 1 ops*** ****** 0 Apr 20 11:53 test99 /export/home/ops***/test: ls -l total 4... (9 Replies)
Discussion started by: chris01010
9 Replies

5. UNIX for Dummies Questions & Answers

[Solved] Assistance with find command please

Trying to locate files less than xx days old, throughout all directories/subdirectories, but excluding certain types of directories and files. The directories I want to search all contain the same characteristic (dbdef, pldef, ghdef, etc), and there are subdirectories within that I need to... (2 Replies)
Discussion started by: Condmach
2 Replies

6. Shell Programming and Scripting

Assistance on making a report log file

:):):):):) (0 Replies)
Discussion started by: bryan101
0 Replies

7. Red Hat

Identify the folder is part of which mount point

Dear, I am using Redhat 6.6 . How to identify a given directory is part of which mount point. (2 Replies)
Discussion started by: aneesha
2 Replies

8. Shell Programming and Scripting

String variable as part of expression in find command

Hi, I am new in scripting, and I am currently working on a script that will look for other files in a certain directory and exclude some file type. this works fine:Find_File2Exclude=`find ${paths} -maxdepth 1 -type f \( ! -iname '*.out' ! -iname '*.auc' ! -iname '*.cps' ! -iname '*.log' ! -iname... (4 Replies)
Discussion started by: kedd05
4 Replies

9. UNIX for Beginners Questions & Answers

Assistance with my one line command to find all inactive kernels

Hello Forum, I'm using the following command to find all inactive kernels installed on my RHEL server: $ rpm -qa | grep '^kernel-' |grep -vE `uname -r` but the result is in two lines: kernel-3.10.0-1062.1.1.el7.x86_64 kernel-3.10.0-1062.el7.x86_64 Is there a one line command I can... (3 Replies)
Discussion started by: greavette
3 Replies
CHEF-SOLO(8)							    Chef Manual 						      CHEF-SOLO(8)

NAME
chef-solo - Runs chef in solo mode against a specified cookbook location. SYNOPSIS
chef-solo (options) -c, --config CONFIG The configuration file to use -d, --daemonize Daemonize the process -g, --group GROUP Group to set privilege to -i, --interval SECONDS Run chef-client periodically, in seconds -j, --json-attributes JSON_ATTRIBS Load attributes from a JSON file or URL -l, --log_level LEVEL Set the log level (debug, info, warn, error, fatal) -L, --logfile LOGLOCATION Set the log file location, defaults to STDOUT - recommended for daemonizing -N, --node-name NODE_NAME The node name for this client -r, --recipe-url RECIPE_URL Pull down a remote gzipped tarball of recipes and untar it to the cookbook cache. -s, --splay SECONDS The splay time for running at intervals, in seconds -u, --user USER User to set privilege to -v, --version Show chef version -h, --help Show this message DESCRIPTION
Chef Solo allows you to run Chef Cookbooks in the absence of a Chef Server. To do this, the complete cookbook needs to be present on disk. By default Chef Solo will look in /etc/chef/solo.rb for its configuration. This configuration file has two required variables: file_cache_path and cookbook_path. For example: file_cache_path "/var/chef-solo" cookbook_path "/var/chef-solo/cookbooks" For your own systems, you can change this to reflect any directory you like, but you'll need to specify absolute paths and the cook- book_path directory should be a subdirectory of the file_cache_path. You can also specify cookbook_path as an array, passing multiple locations to search for cookbooks. For example: file_cache_path "/var/chef-solo" cookbook_path ["/var/chef-solo/cookbooks", "/var/chef-solo/site-cookbooks"] Note that earlier entries are now overridden by later ones. Since chef-solo doesn't have any interaction with a Chef Server, you'll need to specify node-specifc attributes in a JSON file. This can be located on the target system itself, or it can be stored on a remote server such as S3, or a web server on your network. Within the JSON file, you'll also specify the recipes that Chef should run in the "run_list". An example JSON file, which sets a resolv.conf: { "resolver": { "nameservers": [ "10.0.0.1" ], "search":"int.example.com" }, "run_list": [ "recipe[resolver]" ] } Then you can run chef-solo with -j to specify the JSON file. It will look for cookbooks in the cookbook_path configured in the configura- tion file, and apply attributes and use the run_list from the JSON file specified. You can use -c to specify the path to the configuration file (if you don't want chef-solo to use the default). You can also specify -r for a cookbook tarball. For example: chef-solo -c ~/solo.rb -j ~/node.json -r http://www.example.com/chef-solo.tar.gz In the above case, chef-solo would extract the tarball to your specified cookbook_path, use ~/solo.rb as the configuration file, and apply attributes and use the run_list from ~/node.json. SEE ALSO
Full documentation for Chef and chef-solo is located on the Chef wiki, http://wiki.opscode.com/display/chef/Home. AUTHOR
Chef was written by Adam Jacob adam@ospcode.com of Opscode (http://www.opscode.com), with contributions from the community. This manual page was written by Joshua Timberman joshua@opscode.com with help2man. Permission is granted to copy, distribute and / or modify this docu- ment under the terms of the Apache 2.0 License. On Debian systems, the complete text of the Apache 2.0 License can be found in /usr/share/common-licenses/Apache-2.0. Chef 10.12.0 June 2012 CHEF-SOLO(8)
All times are GMT -4. The time now is 09:11 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy