How do I run this shell script? - shell

I'm using this script:
https://github.com/gilleswittenberg/BackupSql/blob/master/BackupSqlShell.php
But when I run cake BackupSql from my terminal within my console folder I get this error:
Error: Shell class BackupSqlShell could not be found.
I have put BackupSqlShell.php inside app/Console/Command/
Am I doing this right?

You should run shells in 2.x as follows (from the app dir):
Console/cake FooBar
You can run Console/cake which will output what is available. Try it and see if your shell is showing.
If it is, make sure you type it correctly, copy paste to be sure.
If its not, check permissions and location is 100% correct, eg: case and so on.
Edit: You can not, ever, run shells from Console/Command. always from APP dir.

Related

Getting the true work directory when running ruby through an alias

I created an alias so that I can run my ruby script from any directory.
alias run_me="ruby ~/mycli/script.rb"
However now the File.dirname doesn't work correctly. When my script runs from the alias, and executes File.dirname(File.realpath(__FILE__)), I always get the wrong directory. I get the directory of the ruby script file but not where my terminal actually is.
The following code outputs ~/mycli but I was expecting ~/some_random_directory. How can I change this behavior?
cd ~/some_random_directory
run_me
I suggest:
File.basename(Dir.getwd)

Trouble installing haskell: how to adjust PATH variable to add to a shell config file?

I installed Haskell on my MacOS system using ghcup installer. It worked because if I type ghci I am dropped into this interactive shell. However I got this message in the terminal after doing the install:
In order to run ghc and cabal, you need to adjust your PATH variable.
You may want to source '/Users/user1/.ghcup/env' in your shell
configuration to do so (e.g. ~/.bashrc).
Detected bash shell on your system...
If you want ghcup to automatically add the required PATH variable to "/Users/user1/.bashrc"
answer with YES, otherwise with NO and press ENTER.
YES
grep: /Users/user1/.bashrc: No such file or directory
My shell is bash 3.2 But as you can see, when I typed YES it says there is no such file. How do I find my shell configuration file, or resolve this? I'd like to complete the setup correctly here.
And I have to be honest about my level of knowledge here, I don't truly understand what this is asking exactly. Is the PATH variable 'env'?
On macOS, .bashrc does not exist by default. ghcup will create this file, so the command you ran will have worked correctly. However, one of ghcup's subcommands expected to find the file before it was created, and therefore reported that error message. You can safely ignore this.

Script shell to automate deployment site

I'm trying to write a script shell (Mac OS X) for deploying my Awestruct site within a launch agent.
So, I have to generate site before deploying it. The command to generate site is :
awestruct -g
My script is myscript.sh :
cd /my/site/structure/base/directory
awestruct -g
This script is launched by the system when an event occurs.
But the problem is it doesn't know about awestruct...
My awestruct program is a part of my ruby installation and is added to my PATH variable.
When I run the script manually, it works (because it's my user who is lauynching it)
When the system detect the event and runs the script, it results as :
awestruct: command not found
The problem is the PATH...
If it works manually, then in the same prompt where it works, run command:
which awestruct
That will print the program file with full path, let's assume /usr/local/bin/awestruct, but use whatever it really is. Then use that in your script, for example:
cd /my/site/structure/base/directory
/usr/local/bin/awestruct -g
This assumes that there are no other environment variables, only defined for your account, which awestruct needs. If there are, then find out what they are, and add them to your script before running awestruct, for example with line:
export AWESTRUCT_ENVIRONMENT_VARIABLE=foobar
(Note: When you run the script normally like any program, that will not change the parent shell environment.)
You can also add the path to the executable in the PATH of the user that run the script and gets the error.
You could try something like :
$ su - <user_that_run_the_script>
$ echo "export PATH=$PATH:$(which awestruct)" >> ~/.bash_profile
$ source ~/.bash_profile
(For Linux users, use ~/.bashrc instead of ~/.bash_profile)

Command Not Found when writing a Node Shell Script

I am attempting to create a shell script using Node.js similar to packages like express and mocha. My initial test reported command not found so I backed the script to the following:
#!/usr/bin/env node
console.log("printing stuff");
The above should just output "printing stuff" when ran; however, that too doesn't work.
I'm attempting to execute the script via ./script in the directory of the file in order to ensure it's not a pathing issue. Attempting to execute under a privileged state (i.e. sudo) yields the same results/error message.
Any idea what I need to do?
When you shebang (#!) /usr/bin/env node, you are saying "look for a program called node on my PATH". If doing node -v works, as #Ryan says, the shebang should work fine. Any chance you have a shell alias or shell function named node? That could be giving you the illusion that your PATH is correct even when it is not. But essentially, just make sure the directory where the node binary lives (the bin directory under your node install) is on your PATH environment variable, and things really should work at that point.
export PATH=/usr/local/node/bin:$PATH
Figured out my issue. I made the shell script but forgot to set execute permissions onto the file. doing a chmod a+x script resolved the issue.

Is there a way to convert ruby scripts to executable(linuxmint)

Hey guys, I run LinuxMint and I have some scripts which I want to run without terminal, can you tell me how?
You need to:
Put as the first line of your ruby script the following shebang line (so bash knows what program to use to run this file)
#!/usr/bin/env ruby
Make your ruby file executable. In a console you can do this:
chmod 700 my_ruby_file.rb
Test that your ruby file is now executable. In a console write:
./my_ruby_file.rb
Notice that we are no longer calling "ruby my_ruby_file.rb", but instead just call the file directly "./my_ruby_file.rb"
If your ruby program executed normally, then everything is going well. If it does not execute and shows you an error, then something is not well done from the previous steps (and post your error)
In your desktop, create an application link, and point it to the my_ruby_file.rb
Once you have the application icon created and shown in your desktop, you can doble-clickit and it will run your application.
Tell us how it went- cheers

Resources