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
SHEF(1) 							    Chef Manual 							   SHEF(1)

NAME
shef - Interactive Chef Console SYNOPSIS
shef [named configuration] (options) -S, --server CHEF_SERVER_URL The chef server URL -z, --client chef-client mode -c, --config CONFIG The configuration file to use -j, --json-attributes JSON_ATTRIBS Load attributes from a JSON file or URL -l, --log-level LOG_LEVEL Set the logging level -s, --solo chef-solo shef session -a, --standalone standalone shef session -v, --version Show chef version -h, --help Show command options When no --config option is specified, shef attempts to load a default configuration file: o If a named configuration is given, shef will load ~/.chef/named configuration/shef.rb o If no named configuration is given shef will load ~/.chef/shef.rb if it exists o Shef falls back to loading /etc/chef/client.rb or /etc/chef/solo.rb if -z or -s options are given and no shef.rb can be found. o The --config option takes precedence over implicit configuration paths. DESCRIPTION
shef is an irb(1) (interactive ruby) session customized for Chef. shef serves two primary functions: it provides a means to interact with a Chef Server interactively using a convenient DSL; it allows you to define and run Chef recipes interactively. SYNTAX
Shef uses irb's subsession feature to provide multiple modes of interaction. In addition to the primary mode which is entered on start, recipe and attributes modes are available. PRIMARY MODE
The following commands are available in the primary session: help Prints a list of available commands version Prints the Chef version recipe Switches to recipe mode attributes Switches to attributes mode run_chef Initiates a chef run reset reinitializes shef echo :on|:off Turns irb's echo function on or off. Echo is on by default. tracing :on|:off Turns irb's function tracing feature on or off. Tracing is extremely verbose and expected to be of interest primarily to developers. node Returns the node object for the current host. See knife-node(1) for more information about nodes. ohai Prints the attributes of node In addition to these commands, shef provides a DSL for accessing data on the Chef Server. When working with remote data in shef, you chain method calls in the form object type.operation, where object type is in plural form. The following object types are available: o nodes o roles o data_bags o clients o cookbooks For each object type the following operations are available: object type.all(&block) Loads all items from the server. If the optional code block is given, each item will be passed to the block and the results returned, similar to ruby's Enumerable#map method. object type.show(object name) Aliased as object type.load Loads the singular item identified by object name. object type.search(query, &block) Aliased as object type.find Runs a search against the server and returns the matching items. If the optional code block is given each item will be passed to the block and the results returned. The query may be a Solr/Lucene format query given as a String, or a Hash of conditions. If a Hash is given, the options will be ANDed together. To join conditions with OR, use negative queries, or any advanced search syntax, you must provide give the query in String form. object type.transform(:all|query, &block) Aliased as object type.bulk_edit Bulk edit objects by processing them with the (required) code block. You can edit all objects of the given type by passing the Sym- bol :all as the argument, or only a subset by passing a query as the argument. The query is evaluated in the same way as with search. The return value of the code block is used to alter the behavior of transform. If the value returned from the block is nil or false, the object will not be saved. Otherwise, the object is saved after being passed to the block. This behavior can be exploited to cre- ate a dry run to test a data transformation. RECIPE MODE
Recipe mode implements Chef's recipe DSL. Exhaustively documenting this DSL is outside the scope of this document. See the following pages in the Chef documentation for more information: o http://wiki.opscode.com/display/chef/Resources o http://wiki.opscode.com/display/chef/Recipes Once you have defined resources in the recipe, you can trigger a convergence run via run_chef EXAMPLES
o A "Hello World" interactive recipe chef > recipe chef:recipe > echo :off chef:recipe > file "/tmp/hello_world" chef:recipe > run_chef [Sat, 09 Apr 2011 08:56:56 -0700] INFO: Processing file[/tmp/hello_world] action create ((irb#1) line 2) [Sat, 09 Apr 2011 08:56:56 -0700] INFO: file[/tmp/hello_world] created file /tmp/hello_world chef:recipe > pp ls '/tmp' [".", "..", "hello_world"] o Search for nodes by role, and print their IP addresses chef > nodes.find(:roles => 'monitoring-server') {|n| n[:ipaddress] } => ["10.254.199.5"] o Remove the role obsolete from every node in the system chef > nodes.transform(:all) {|n| n.run_list.delete('role[obsolete]') } => [node[chef098b2.opschef.com], node[ree-woot], node[graphite-dev], node[fluke.localdomain], node[ghost.local], node[kallistec]] BUGS
The name shef is clever in print but is confusing when spoken aloud. Pronouncing shef as chef console is an imperfect workaround. shef often does not perfectly replicate the context in which chef-client(8) configures a host, which may lead to discrepancies in observed behavior. shef has to duplicate much code from chef-client's internal libraries and may become out of sync with the behavior of those libraries. SEE ALSO
chef-client(8) knife(1) http://wiki.opscode.com/display/chef/Shef AUTHOR
Chef was written by Adam Jacob adam@opscode.com with many contributions from the community. Shef was written by Daniel DeLeo. DOCUMENTATION
This manual page was written by Daniel DeLeo dan@opscode.com. Permission is granted to copy, distribute and / or modify this document under the terms of the Apache 2.0 License. CHEF
Shef is distributed with Chef. http://wiki.opscode.com/display/chef/Home Chef 10.12.0 June 2012 SHEF(1)
All times are GMT -4. The time now is 01:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy