cron tab to execute rails commands - mysql

i am running a cron tab for every 5 minutes,it contains an .sh files which need to be executed ,where that .sh file consists of ruby code....one thing i can't understand that when i am executing the .sh file directly in terminal its get execute,but the same thing in crontab fails..my entry in crontab follows :
1) mysqldump -uroot -p'myPassword' redmine144 > redmine144_$(date +%Y_%m_%d_%H_%M).sql;
2) cd /home/ror/Projects/redmine144/;
source /usr/local/rvm/environments/ruby-1.9.3-p194#redmine144
bundle exec rake "hb:project_progress"
First one to take backup and it is working fine.
Second one to run some ruby rake task(not working form cron tab)

usually crontab output in not directed to stdout so you check your out put in /var/log/cron file which contains the cron logs. you can add the output and redirect the error, for more see http://www.thegeekstuff.com/2012/07/crontab-log/ and check what error pops upp and you'll be able to figure it out...

Making RVM work with cron is really tricky. I'll share a snippet from my own crontab that is proven to work (with system-wide RVM) - just make sure your app path has a .rvmrc specifying the ruby version and gemset.
MAILTO=mymail#gmail.com
SHELL=/bin/bash
? ? ? ? ? source /etc/profile.d/rvm.sh; cd /app/home/path && bundle exec rake whatever_you_need RAILS_ENV=production
SHELL is important.
The MAILTO is there to aid debugging and could be removed later.
Don't forget to substitute your schedule for the question marks.

Related

Using command line to open, edit and save content in file

During the work, there are a lot of partners in the project, and sometimes I need to switch among different partners a lot, and every time the process:
change the partner name in .env file manually
run docker-compose down in the terminal
run docker-compose up -d in the terminal
run gulp dev --partner <partner name> in the terminal
So my question is :
Would it possible to use one line of command to complete the entire above process (such as in the package.json, "docker": "docker-compose down && docker-compose up -d", then npm run docker means running docker down and up)
Basically the main point should be :
Would it be possible to use command line to open, edit and save a file? (I know I could use command line to open vi, and then to edit inside vi, but here is not the case)
There's certainly methods of text editing from the command line (see sed/awk etc.) My solution to this, would be to have multiple .env files:
e.g. .env.alice; .env.bob; .env.charlie
Then as part of my script I would symbolically link the one I wanted:
ln -sf .env.alice .env
The rest as you described.

PHP Mysql laravel 5.4 terminal issue

i am new to laravel i just figured out how to install composer laravel etc etc on my local machine MAMP on windows , Now i am confuse with the command on terminal which is
C:\project>mysql -uroot -proot
'mysql' is not recognized as an internal or external command,
operable program or batch file.
How can i fix this ?
setting Environment will solve the issue
Go to Control Panel -> System -> Advanced
Click - Environment Variables
Go to- System Variables find PATH and click on it.
add the path to your mysql\bin folder to the end paths. (ex: E:\xampp\mysql\bin) and add ; end of the line
Close all the command prompts you opens.
Re open and try it.
Setting the PATH to point to the MYSQL bin folder is normally the first thought, but I find that dangerous as things get left lying around when you change software.
I normally create a little batch file in the projects folder or in a folder that it already on your PATH, like this
mysqlpath.cmd
echo off
PATH=C:\mamp\path\to\the\mysql\bin;%PATH%
mysql -v
The mysql -v will output the mysql version number but it is a handy way of knowing that the correct folder has been added to the PATH. This adds the folder to the PATH but only for the life of the command window.
Then just run this from any command window when you want to use MYSQL from the command line
> phppath
You may also like to create one for PHP as well
phppath.cmd
echo off
PATH=C:\mamp\path\to\the\php\;%PATH%
php -v

Openshift Cronjob Not Running

I have tried to setup a simple cron job running on openshift but once I have pushed the file to openshift and then login and search for the file it does not seem to be there and there is not log output.
I created an application from: https://github.com/smarterclayton/openshift-go-cart
I then installed the cron 1.4 cartridge.
I created a file at .openshift/cron/minutely/awesome_job and set it as 755
I added the following contents:
#! /bin/bash
date > $OPENSHIFT_LOG_DIR/last_date_cron_ran
I pushed to the server
Logged in via ssh and run find /var/lib/openshift/53760892e0b8cdb5e9000b22 -name awesome_job for which it finds nothing.
Any ideas which might help as I am at loss why is it not working.
Make sure the execution bit is set on your cron file.
The issue was not with cron but with the golang cartridge I was using which was removing the .openshift directory.
https://github.com/smarterclayton/openshift-go-cart/issues/10
You should also put a file named "jobs.allow" under your .openshift/cron/minutely/. So your cron jobs will be executed.
For your ref: https://forums.openshift.com/daily-cron-jobs-not-getting-triggered-automatically
And the reason you can find your awesome_job vis ssh login is because it is under /var/lib/openshift/53760892e0b8cdb5e9000b22/app-root/runtime/repo/.openshift, so the command find does not search any files under folders named with . prefixed.

mysql system command

I am in MySQL and would like to change the current working directory. I tried to execute:
mysql> system cd './my_dir'
However, this does not seem to work. Has anyone run into a similar problem?
System is going to spawn a child process to run a shell command.....
Current working directory is a process level property....so you can't change it in the parent from a child process. That's why it doesn't work.
I briefly scanned the MySQL docs at http://dev.mysql.com/doc/refman/5.5/en/mysql-commands.html but didn't see a direct CD command that changes the working directory. I think an adventurous person could write one....
If you want to change your current working directory for a script, then use the && between the CD and script so it will change directory and then if that's successful it will execute the second command.
mysql> SYSTEM cd /home && ls
What you're looking for is the escape to shell command: \!
mysql>\! cd ./my_dir
You can even use it to escape to the shell completely and then come back to the mysql environment.
mysql>\! bash
bash>cd ./my_dir
bash>exit
mysql>SELECT * ALL FROM <table>;

(Doctrine-Ubuntu) Get error: doctrine-cli.php: command not found

(Doctrine-Ubuntu) I run $ doctrine-cli.php command and get doctrine-cli.php: command not found.
P
What's the exactly command you're executing? It should be something like this:
php doctrine-cli.php COMMAND
Also php should be available under PATH system variable but in Ubuntu (if you installed PHP by package installer) that's done by default.
Do this in the command line if you just want to execute it:
chmod +x doctrine-cli.php
and optionally
cp doctrine-cli.php doctrine
this way you can do
./doctrine-cli.php [arguments]
and if you did the optional step you can do
./doctrine [arguments]
and if you don't want the ./ do this
export PATH=$PATH:/full/path/to/doctrine/folder
so now you can execute the doctrine command from any folder
What this does is adds the 'execute' permission to the file. If you have a proper shebang on the top of the file everything should execute fine (I imagine it does) and optionally adds the doctrine folder to your PATH so you can execute it from anywhere