Knife command works from one particular directory but not from others. why? - ruby

I have created an organization called "kaushikinc" on chef server and have a directory structure "C:/x/y/z/kaushikinc".
When I execute a command from kaushikinc folder, they work fine but when I execute from a parent or child folder, they dont work. What am I doing wrong?
Ex: from a child folder: No success or error message:
But a success when I try from kaushikinc folder
Edit: Adding a new image to show that the problem exists even when I pass the location of knife.rb config file
Edit2: I run across this problem only when I use "--all" option on "knife data bag from file" command. I am able to execute any other command from any directory with -c enabled.

Usually, this is because the directory you're in, or a parent directory, contains a .chef directory. knife searches for .chef in:
./.chef (current directory contains .chef)
~/.chef (homedir contains .chef)
parent directories (e.g. ./.. then ./../.. all the way back to /)
You can see some of the logic itself here.

Related

Shell script to create directory from any random directory

I am currently in /Desktop on my ubuntu system and I want to create a directory named vip inside /Documents/subd. Please not that Documents and Desktop are at same level. But the crux of this question is that I have to write a shell script such that it can create the requied directory from any directory of the system, no matter where it is situated.
I have tried concatenating $home with the required directory path!! But it is not working.
mkdir $home."/Documents/subd/vip"
I need to run this inside /Desktop or any other directory.
Please guide me!!
This should do the job:
mkdir "$HOME/Documents/subd/vip"
You just had some minor errors in your command.

Delete only directory contents using chef

Is there a way I can delete only the contents of a directory without deleting the actual parent directory? When I use recursive and action delete, the actual parent directory is also getting deleted.
If I specify a path C:\chef\mydir, then all the contents of this dir (files and sub directories) must get deleted, basically emptying. I am in a Windows environment.
Any guidance in the right direction would be much appreciated.
There isn't a great way to do this in Chef (or even just in raw Ruby). You can crib from my code though: https://github.com/poise/poise-archive/blob/master/lib/poise_archive/archive_providers/base.rb#L115-L119
Just put that in a ruby_block and you should be okay.
In linux you can run something like rm -r dir/**/* to delete all the files in the directory. This won't delete the parent directory. You can add this to chef recipe.
I am not sure about windows but you can try:
Actions This resource has the following actions:
:nothing
Prevent a command from running. This action is used to
specify that a command is run only when another resource notifies it.
:run Default.
Run a command.
execute "delete_files" do
command "del /s /q /F *"
cwd "C:\chef\mydir"
end
Delete single file:
file 'delete_files' do
path 'C:\\chef\\mydir\\my.file'
action :delete
end
Please let me know if it works.
With my limited knowledge of Chef, I did the following as I knew how to delete an entire directory and how to create new directories. The approach taken was to delete the directory and then recreate the same directory, instead of trying to "empty" it. This may be crude, but it served my purpose.
directory my_temp_dir do
recursive true
action [:delete, :create]
only_if {::Dir.exist?(my_temp_dir)}
end
The create action will execute only after the delete action and the condition "directory must exist" has to be satisfied. This way, we can ensure directories are not unnecessarily created on servers as the ultimate objective is to "empty" the directory.

How to call nested script in sqlplus

I have following script hierarchy.
Scripts/master.sql
Scripts/GB/gb.sql
Scripts/GB/user1/insert.sql
master.sql contains simple #script to call gb.sql
e.g.
#GB/gb.sql
gb.sql contains below
#user1/insert.sql
The problem is that if i run master.sql from Scripts directory, i get below error:
unable to find insert.sql
Whereas if I execute gb.sql from GB directory, ir run successfully.
Can you please help me?
SQL*Plus directories are always reletive to the original working directory. Your scripts will need to repeat the full path from the working directory each time.
Change gb.sql to:
#GB/user1/insert.sql
The ## can be used to reference files in the same directory as the running file, but ## does not work with sub directories.

Unable to create /root/.config/<app> programmatically

I've built a script that places an icon in the launcher to open a program as the root user. This script also adds NOPASSWD to the user's configuration for this specific app in /etc/sudoers, however the one part of the script that refuses to work is the creation of the profile in /root/.config/<app>. I can create this manually, using the same mkdir command, but when I place the same command in the script it returns no such file or directory. I have replicated this behaviour a number of times, including on a clean install.
Is there some form of protection that disallows the ability to automate the creation of this directory? Or am I missing something about hidden folders in Linux?
I assume you are doing this when the .config dir does not exist yet.
mkdir /root/.config/<app>
Try this :
mkdir -p /root/.config/<app>
This will create any missing parent directory to the full path you provide.

Refer to a directory in your working directory

I'm working on the Mac Terminal with the program called QIIME. However, my question is more related to basic navigating in the terminal.
When I enter a command, and would like to refer to a file that is located in a directory/map inside my current working directory, how do I do this?
For example:
convert_fastaqual_fastq.py -f sequenceA.fastq
Now sequenceA is located in a map in my working directory, so I guess I'll have to add arguments before sequenceA.qual, or shouldn't I ?
from your working directory you should be able to access that file with:
the_directory_your_file_is_in/sequenceA.qual
else, you could use something like:
./the_directory_your_file_is_in/sequenceA.qual
A point stands for the directory your are currently in.
../the-directory-you-are-in/the_directory_your_file_is_in/sequenceA.qual
Two points stand for the directory above your current directory.

Resources