Cron jobs...

I set crontabs before on debian and Ubuntu.
Now i am trying to do the same stuff with opensuse.
what i want to do is:
I have php files, i want to run it after 5 minutes by cron.
So far i have this:

*/5 * * * * /usr/bin/php /var/www/monitoring/cron.php

Which was working fine before on other systems.
I have to configure crontab in terminal like:

crontab -e

But when i try to type this ‘*’, what i get is :

E348: No string under cursor

Any ideas, i face this before and solved it, but now out of my mind.
Does any body have idea of multiple crons, mean just write all cron jobs in a file and run that file by cron.
I have some idea.
file:

*/5 * * * * /usr/bin/php /var/www/monitoring/cron.php
*/5 * * * * /usr/bin/php /var/www/monitoring/vibration.php

Now run it under cron like:

*/5 * * * * /var/www/monitoring/file.txt

Is it correct.

All ideas are welcomed.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The “error” about ‘No string under cursor’ is because you are using ‘vi’
or ‘vim’ for editing your crontab and you are in command mode instead of
insert mode. Before you put your ‘*’ on the line type ‘i’ which will
put you in the mode to insert text. Then enter your entire line and,
when done, press the [Esc] key. At this point either enter the following:

:wq!

or hold [Shift] and press the ‘z’ key twice

ZZ

Good luck.

mmarif4u wrote:
> I set crontabs before on debian and Ubuntu.
> Now i am trying to do the same stuff with opensuse.
> what i want to do is:
> I have php files, i want to run it after 5 minutes by cron.
> So far i have this:
>> /5 * * * * /usr/bin/php /var/www/monitoring/cron.php
> Which was working fine before on other systems.
> I have to configure crontab in terminal like:
>> crontab -e
> But when i try to type this '
’, what i get is :
>> E348: No string under cursor
> Any ideas, i face this before and solved it, but now out of my mind.
> Does any body have idea of multiple crons, mean just write all cron
> jobs in a file and run that file by cron.
> I have some idea.
> file:
>> */5 * * * * /usr/bin/php /var/www/monitoring/cron.php
>> */5 * * * * /usr/bin/php /var/www/monitoring/vibration.php
>>
> Now run it under cron like:
>> */5 * * * * /var/www/monitoring/file.txt
>>
> Is it correct.
>
> All ideas are welcomed.
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIxgOd3s42bA80+9kRAghxAJ48ywdaB6EPONTU+H79BiLHFdwlIACghrD7
2dD+D0oKwpvcdWUNe7E0Gzc=
=0Op5
-----END PGP SIGNATURE-----

If you do a google for “no string under cursor” you will get this hit:

Tip #1 - the super star : vim online

It simply means you have not entered insert mode in vim, so the * is treated as a command meaning search forward for word under cursor. Tip: the # key does the same in the reverse direction.

Vim is a very powerful editor with lots of programmer oriented short command sequences. If you are not familiar with vim, perhaps you should use a simpler editor like nano or joe. You can set your preferred visual editor with “export VISUAL=nano” in ~/.bashrc.

Does any body have idea of multiple crons, mean just write all cron jobs in a file and run that file by cron.

Just put multiple lines in your crontab like you have posted, that’s the simplest way.

*/5 * * * * /usr/bin/php /var/www/monitoring/cron.php
*/5 * * * * /usr/bin/php /var/www/monitoring/vibration.php

Thanks ab@novell.com.
I forgot the I and zz method. now its working fine.

@ken_yap:
Thanks to you to for a detailed post specially export.
Can i put gedit as a editor there.
~/.bashrc will be from my home dir.am i right.

gedit, I dunno, probably, but then you will only be able to edit when you have a GUI desktop running.

Thanks for the info.
I tried to run the multiple crons in a file.
what i get in the mail is:

/var/www/CSL_monitoring_2/cron.txt: line 1: */2: No such file or directory
/var/www/CSL_monitoring_2/cron.txt: line 2: */2: No such file or directory

file is cron.txt:

*/2 * * * * /usr/bin/php /var/www/monitoring_2/cron.php
*/2 * * * * /usr/bin/php /var/www/monitoring_2/cron_vibration.php

cron is:

*/2 * * * * /var/www/CSL_monitoring_2/cron.txt

all files are in the same dir.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Um, I think we have a bit of confusion here. The line where you are
trying to execute what appears to be a text file? That doesn’t make any
sense… put the lines that call the ‘php’ executable directly in the
resulting window from your ‘crontab -e’ command. Those lines would be,
per your post:

*/2 * * * * /usr/bin/php /var/www/monitoring_2/cron.php
*/2 * * * * /usr/bin/php /var/www/monitoring_2/cron_vibration.php

The ‘crontab -e’ isn’t looking for you to specify a file that will be
interpreted by cron… it is the file/configuration to be interpreted
by cron. Anyway, put the lines above in there.

Also, about the file not existing, you mentioned all files were in the
same directory, but these are not the same directories:

/var/www/monitoring_2/
/var/www/CSL_monitoring_2/

One of them has ‘CSL’ in it, which is apparently wrong.

Good luck.

mmarif4u wrote:
> Thanks for the info.
> I tried to run the multiple crons in a file.
> what i get in the mail is:
>> /var/www/CSL_monitoring_2/cron.txt: line 1: */2: No such file or
>> directory
>> /var/www/CSL_monitoring_2/cron.txt: line 2: */2: No such file or
>> directory
>>
> file is cron.txt:
>> */2 * * * * /usr/bin/php /var/www/monitoring_2/cron.php
>> */2 * * * * /usr/bin/php /var/www/monitoring_2/cron_vibration.php
>
> cron is:
>> */2 * * * * /var/www/CSL_monitoring_2/cron.txt
>
> all files are in the same dir.
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIxhPV3s42bA80+9kRAieIAJ9R62yLEjNrhUPgdNy/gKmyAZfb0gCfSG7K
IkmN0BUgbsIGEOucB9FNObY=
=NhgP
-----END PGP SIGNATURE-----

No, don’t bother with cron.txt, just put those two lines directly in the crontab, that’s what I was trying to tell you.

*/2 * * * * /usr/bin/php /var/www/monitoring_2/cron.php
*/2 * * * * /usr/bin/php /var/www/monitoring_2/cron_vibration.php 

@ken_yap
I understand what you said in last post. but i was trying to do it like that way.i did that before in ubuntu, and was working fine.
i know about to put multiple lines in cron.I tried because some time we use crontab -r, which will delete all the lines there. but having in a file, you can add one file each time. Also editing is easy.
Anyway, thanks for the ideas.
Will try to go around it more.

@ab@novell.com
The directory was same, i mistakenly changed it in that post.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

While the abilitiy to chain configs indefinitely may be possible, it
doesn’t make much sense unless you are blocking the ability for
individual users to use cron on their own (e.g. via crontab -e) since
it requires not provides the opportunity for a lot of confusion, it also
means (in most cases) you aren’t giving anything new except that
complexity. The cron daemon also needs to recognize something as NOT an
executable but instead as a config file, which could be done a few ways
but could also be tricky to implement. I’m not sure I can think of a
reason why chaining them would be helpful except in how SUSE already
does it for the root user, of sorts, using /etc/cron.daily,
/etc/cron.hourly, etc. These directories don’t contain additional cron
configurations but instead have the actual scripts that are to be run
per time period (by directory name) directly, which is convenient when
you want a daily script since you just drop it in /etc/cron.daily and
let the system take care of it. Again, this is for the ‘root’ user.
Any other user can add as many lines as they like to their own
configuration (assuming cron is enabled for them, which may not be the
case) by using the crontab -e command you’ve been using. This runs
anything in there as that user and is up to them entirely what they do
without any other administrator intervention.

Good luck.

mmarif4u wrote:
> @ken_yap
> I understand what you said in last post. but i was trying to do it like
> that way.i did that before in ubuntu, and was working fine.
> i know about to put multiple lines in cron.I tried because some time we
> use crontab -r, which will delete all the lines there. but having in a
> file, you can add one file each time. Also editing is easy.
> Anyway, thanks for the ideas.
> Will try to go around it more.
>
> @ab@novell.com
> The directory was same, i mistakenly changed it in that post.
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIxhsK3s42bA80+9kRAs1jAJsFXyUMjixkf4lvjehabmfKCnzlCACghGJT
Pwq4cKlgu60FdCtw/b8UWwk=
=974K
-----END PGP SIGNATURE-----

I don’t see what the problem is. You can edit the crontab using the same editors as any normal file. If you put both commands in one file, you are committed to running those jobs at the same intervals. More seriously, if you put the two commands in one file like this:

#!/bin/sh
/usr/bin/php /var/www/monitoring_2/cron.php
/usr/bin/php /var/www/monitoring_2/cron_vibration.p

you are running them in sequence, which means that if the first job takes a minute to finish, the second one doesn’t start until then, which may throw your timing out. Whereas with both lines in the cron job, both jobs are started at the same time.

This now make sense.
Thanks for the valuable information.
i will put as mentioned by you and ab@novell.com.
I think that is the better way.

Yes thats correct. The jobs will be run in sequence. But there is a clean work-around for this

#!/bin/sh
/usr/bin/php /var/www/monitoring_2/cron.php &
/usr/bin/php /var/www/monitoring_2/cron_vibration.php &

Notice the “&” at the end of each line. This will make the php process run in background. This way both the jobs will be run parallelly and not in sequence. This should do the trick.

PS: I would prefer looping over the list of php files that have to be run.