Unable to run cron job with standard user account - cron

The same job can be executed as root, but it can't execute as a standard user.
Is it permission problem or I need to change anything, I have no idea on it.
Thanks
SunOS 5.10 Generic_150400-30 sun4v sparc SUNW,SPARC-Enterprise-T5120
Command:
1) login as a root
2) crontab -l
* * * * * /usr/bin/date > /tmp/root.log
3) /tmp/root.log is here
1) login as a Non-root user
2) crontab -l
* * * * * /usr/bin/date > /tmp/non-root.log
3) /tmp/non-root.log is not here

The following permissions are OK for the binary file date
-bash-3.2# ls -l /usr/bin/date
-r-xr-xr-x 1 root bin 11056 Jan 22 2005 /usr/bin/date
-bash-3.2#
If the permissions are OK check your cron log on /var/cron/log file
-bash-3.2# tail /var/cron/log
< root 24592 c Fri Oct 20 18:50:21 2017
> CMD: /usr/bin/date > /tmp/non-root.log
> user 25192 c Fri Oct 20 18:51:00 2017
< user 25192 c Fri Oct 20 18:51:00 2017
> CMD: /scripts/collectdata.sh > /dev/null 2>&1
> root 25769 c Fri Oct 20 18:52:00 2017
< root 25769 c Fri Oct 20 18:52:00 2017
> CMD: /scripts/collectdata.sh > /dev/null 2>&1
> root 26853 c Fri Oct 20 18:54:00 2017
< root 26853 c Fri Oct 20 18:54:00 2017
-bash-3.2#

Thanks all, I finally found out the issue.
The reason is that non-root account is locked out, I think it maybe someone did many failure attempt which make this locked.
After I passwd -u "Account", the job can be run as expected. Thanks~

Related

Cron script executed but no output

I've taken a look to many different topics and did not find an answer to my problem. I created 2 bash scripts on my Ubuntu server and I'm trying to execute them periodically. It seems they are running, but they produce nothing. They are executable:
drwxr-xr-x 14 root root 4096 Mar 14 18:02 ..
-rwxr-xr-x 1 root root 2623 Apr 16 21:18 backup.pl
-rw-r--r-- 1 root root 87066352 May 10 21:37 full_site_backup-10-4-2018.tar.gz
-rwxr-xr-x 1 root root 530 May 11 20:21 checkHealth.sh
drwxr-xr-x 2 root root 4096 May 11 20:35 .
So here is one of my scripts:
#!/bin/bash
# log stdout and stderr to two different files
exec >>/var/log/test.log 2>>/var/log/test.err.log
# ...and log every command we try to execute to stderr (aka looog.err.log)
# set -x
CODE=$(curl -s -o /dev/null -I -A "myuseragent" -w "%{http_code}" https://www.xxxxxxxxxxxxx.xxx/xxxx)
DATE=$(date)
if [ $CODE -gt 300 ]
then
service mysql restart
service tomcat8 restart
>&2 echo "$DATE - KO !!!!!! code retour $CODE"
else
echo "$DATE - OK, code $CODE"
fi
and here is my sudo crontab -e :
# m h dom mon dow command
0 2 * * * root /usr/bin/perl /var/backup/backup.pl
* * * * * root /bin/sh /var/backup/checkHealth.sh
and here is my sudo tail -f /var/log/cron.log:
May 11 20:39:01 ns381471 CRON[10778]: (root) CMD (root /bin/sh /var/backup/checkHealth.sh)
May 11 20:39:26 ns381471 crontab[10823]: (root) BEGIN EDIT (root)
May 11 20:40:01 ns381471 CRON[10880]: (root) CMD (root /bin/sh /var/backup/checkHealth.sh)
May 11 20:40:01 ns381471 CRON[10879]: (root) CMD (/usr/local/rtm/bin/rtm 2 > /dev/null 2> /dev/null)
May 11 20:40:30 ns381471 crontab[10823]: (root) END EDIT (root)
May 11 20:41:01 ns381471 CRON[10974]: (root) CMD (/usr/local/rtm/bin/rtm 2 > /dev/null 2> /dev/null)
May 11 20:41:01 ns381471 CRON[10975]: (root) CMD (root /bin/sh /var/backup/checkHealth.sh)
May 11 20:42:01 ns381471 CRON[11070]: (root) CMD (/usr/local/rtm/bin/rtm 2 > /dev/null 2> /dev/null)
May 11 20:42:01 ns381471 CRON[11071]: (root) CMD (root /bin/sh /var/backup/checkHealth.sh)
Any help would be appreciated. Thanks
Ok for those who are in the same situation, my crontab was
# m h dom mon dow command
0 2 * * * root /usr/bin/perl /var/backup/backup.pl
* * * * * root /bin/sh /var/backup/checkHealth.sh
It appears that I just copied the syntax you can find on many cron tutorials about editing /etc/crontab, but in my case I did a sudo crontab -e, so I did not have to specifiy the user (root), so the working entries were :
# m h dom mon dow command
0 2 * * * /usr/bin/perl /var/backup/backup.pl
* * * * * /bin/sh /var/backup/checkHealth.sh
or simplier :
# m h dom mon dow command
0 2 * * * /var/backup/backup.pl
* * * * * /var/backup/checkHealth.sh

Crontab throwing error

I have the following content in crontab:
20 1,7,13,18 * * * /usr/sbin/automysqlbackup
15 * * * * root find /opt/activeMq/activemq-data/localhost/KahaDB/ -mtime +10 -type f -delete
but I get this when I restart cron service:
Feb 20 08:43:27 . crontab[14584]: (root) BEGIN EDIT (root)
Feb 20 08:44:08 . crontab[14584]: (root) REPLACE (root)
Feb 20 08:44:08 . crontab[14584]: (root) END EDIT (root)
Feb 20 08:44:28 . kernel: [325740.483115] init: cron main process (14563) killed by TERM signal
Feb 20 08:44:28 . cron[14641]: (CRON) INFO (pidfile fd = 3)
Feb 20 08:44:28 . cron[14642]: (CRON) STARTUP (fork ok)
Feb 20 08:44:28 . cron[14642]: Error: bad username; while reading /etc/crontab
Feb 20 08:44:28 . cron[14642]: (*system*) ERROR (Syntax error, this crontab file will be ignored)
Feb 20 08:44:28 . cron[14642]: (CRON) INFO (Skipping #reboot jobs -- not system startup)
I found the solution. Username field is only available at system level cron(etc/crontab) and not user level cron.

OCaml error: Unbound module Event

I try to build a short ocaml event example. But when I compile, the error in the title appears.
The question of: unbound module Event error when compiling Ocaml game was not helpful for me.
The system is Kubuntu 14.04 and I installed ocaml over aptitude, so installed packages are:
camlp4, ledit, libfindlib-ocaml, libfindlib-ocaml-dev, liboasis-ocaml, liboasis-ocaml-dev, libodn-ocaml, libodn-ocaml-dev, libtype-conv-camlp4-dev, oasis, ocaml, ocaml-base, ocaml-base-nox, ocaml-compiler-libs, ocaml-doc, ocaml-findlib, ocaml-interp, ocaml-native-compilers, ocaml-nox
The OCaml compiler is version 4.01.0
Here is my short test program.
open Thread;;
open Event;;
let chan = Event.new_channel();;
let a () =
Printf.printf "A waiting...\n";;
let sigRX = Event.receive chan in
Printf.printf "A received over channel\n";
let v = Event.sync sigRx in
Printf.printf "A running\n";
Printf.printf "A done!\n";;
let b () =
Thread.delay 0.8
Printf.printf "B sending...\n";;
let sigTX = Event.send "wake up" in
Event.sync sigTX;
Printf.printf "B done!\n";;
let t_a = Thread.create a ();;
let t_b = Thread.create b ();;
I tried to compile this single file (test.ml) with:
ocamlc -thread unix.cma threads.cma test.ml
The response is:
File "test.ml", line 2, characters 0-10:
Error: Unbound module Event
I googled, found some "thread-using-tips" like: http://caml.inria.fr/pub/docs/manual-ocaml/libthreads.html#c%3Athreads
In /usr/lib/ocaml is an threads folder and an thread.mli. Inside the threads folder there are this files:
-rw-r--r-- 1 root root 487 Jan 2 2014 condition.cmi
-rw-r--r-- 1 root root 487 Jan 2 2014 condition.cmx
-rw-r--r-- 1 root root 1203 Jan 2 2014 event.cmi
-rw-r--r-- 1 root root 1867 Jan 2 2014 event.cmx
-rw-r--r-- 1 root root 421 Jan 2 2014 mutex.cmi
-rw-r--r-- 1 root root 407 Jan 2 2014 mutex.cmx
-rw-r--r-- 1 root root 1859 Jan 2 2014 thread.cmi
-rw-r--r-- 1 root root 1308 Jan 2 2014 thread.cmx
-rw-r--r-- 1 root root 62778 Jan 2 2014 threads.a
-rw-r--r-- 1 root root 47047 Jan 2 2014 threads.cma
-rw-r--r-- 1 root root 1258 Jan 2 2014 threads.cmxa
-rw-r--r-- 1 root root 4145 Jan 2 2014 threadUnix.cmi
-rw-r--r-- 1 root root 1515 Jan 2 2014 threadUnix.cmx
What am I missing? I assume, that the Event is packed in Thread Module?
This command line works for me to get past the unbound module problem.
$ ocamlc -I +threads -c test.ml
There are errors in your code, but I imagine you'll know how to fix them.
This full command line will probably work, but I can't be sure because of the errors:
$ ocamlc -thread -I +threads unix.cma threads.cma test.ml
(There are some higher-level tools for building OCaml programs that you might want to learn about at some point.)

gammu-smsd RunOnReceive script results exit status 2

I want to forward an SMS using gammu-smsd RunOnReceive.
That is the script I want to run (/var/spool/gammu/forward.sh) and it goes perfectly if I run it from a sudoer or using sudo -u gammu -g gammu /var/spool/gammu/forward.sh
#!/bin/bash
SMS_MESSAGES=1
for i in `seq $SMS_MESSAGES`
do
number="SMS_${i}_NUMBER"
text="SMS_${i}_TEXT"
eval "gammu-smsd-inject TEXT my_number_goes_here -text \"${!number}: ${!text}\""
done
And here is the problem I am experiencing:
Thu 2015/01/29 23:08:57 gammu-smsd[2549]: Starting run on receive: /var/spool/gammu/forward.sh IN20150130_000850_00_+37368214400_00.txt
Thu 2015/01/29 23:08:57 gammu-smsd[2154]: Process failed with exit status 2
Output of ls -l /etc/gammu-smsdrc /var/spool/gammu/ /usr/bin/gammu-smsd*:
-rw-r--r-- 1 root root 457 Jan 29 22:44 /etc/gammu-smsdrc
-rwxrwxrwx 1 root root 14336 Jun 10 2012 /usr/bin/gammu-smsd
-rwxrwxrwx 1 root root 51164 Jun 10 2012 /usr/bin/gammu-smsd-inject
-rwxrwxrwx 1 root root 9972 Jun 10 2012 /usr/bin/gammu-smsd-monitor
/var/spool/gammu/:
total 24
drwxrwxrwx 2 gammu gammu 4096 Jan 28 16:02 error
-rwxrwxrwx 1 gammu gammu 189 Jan 29 22:13 forward.sh
drwxrwxrwx 2 gammu gammu 4096 Jan 29 23:08 inbox
-rw-rw-r-- 1 gammu gammu 3702 Jan 29 23:08 log
drwxrwxrwx 2 gammu gammu 4096 Jan 29 23:07 outbox
drwxrwxrwx 2 gammu gammu 4096 Jan 29 23:07 sent
What happens if I just do ./forward.sh (not root) - so all is OK:
gammu-smsd-inject[2606]: Created outbox message OUTC20150029_231213_00_my_number_here_sms0.txt
Written message with ID /var/spool/gammu/outbox/OUTC20150029_231213_00_my_number_here_sms0.txt
Here is my /etc/gammu-smsdrc
# Configuration file for Gammu SMS Daemon
[gammu]
port = /dev/ttyUSB0
connection = at
[smsd]
service = files
logfile = /var/spool/gammu/log
debuglevel = 2
commtimeout = 1
sendtimeout = 15
statusfrequency = 0
outboxformat = unicode
transmitformat = unicode
RunOnReceive = /var/spool/gammu/forward.sh
inboxpath = /var/spool/gammu/inbox/
outboxpath = /var/spool/gammu/outbox/
sentsmspath = /var/spool/gammu/sent/
errorsmspath = /var/spool/gammu/error/
ps -fe | grep gammu:
gammu 2154 1 0 23:05 ? 00:00:02 /usr/bin/gammu-smsd --daemon --user gammu --pid /var/run/gammu-smsd.pid
cubie 2644 2403 0 23:20 pts/0 00:00:00 grep gammu
Please, help
I had the same problem and I solved it this way:
First add gammu user to sudoers, with no password:
type: $ sudo visudo
and add: gammu ALL=(ALL) NOPASSWD: ALL
Then run gammu-smsd as root user:
in /etc/init.d/gammu-smsd
change USER=gammu to USER=root
save it and don't forget to restart daemon: service gammu-smsd restart
In RunOnReceive script add sudo in front of gammu-smsd-inject:
e.g.: sudo gammu-smsd-inject TEXT my_tel_num -text "Hello world!"
I hope this will work for you too!
P.S.: I use Gammu version 1.31.90.

procmail disregards /etc/group?

sample procmailrc:
SHELL=/bin/bash
LOGFILE=$HOME/procmail.log
VERBOSE=yes
:0
* ^Subject: envdump please$
{
LOG="`id`"
:0
/dev/null
}
/etc/group file contains (note the other usernames are vain attempts to make this work):
someuser:x:504:
s3:x:505:someuser,someotheruser,postfix,postdrop,mail,root
If I run as "someuser" the command id:
[someuser#lixyz-pqr ~]$ id
uid=504(someuser) gid=504(someuser) groups=504(someuser),505(s3)
However when I run procmail by sending an email with the subject "envdump please", the 505/s3 group disappears (this is in procmail.log):
procmail: [17618] Mon Dec 19 17:39:50 2011
procmail: Match on "^Subject: envdump please$"
procmail: Executing "id"
procmail: Assigning "LOG=uid=504(someuser) gid=504(someuser) groups=504(someuser)"
uid=504(someuser) gid=504(someuser) groups=504(someuser)procmail: Assigning "LASTFOLDER=/dev/null"
this server is running Fedora 14 with Postfix 2.7.5
Procmail wasn't installed setuid.
for background, it should look like:
[root#li321-238 postfix]# ls -l /usr/bin/procmail
-rwsr-sr-x. 1 root mail 92816 Jul 28 2009 /usr/bin/procmail
which you can set up via:
chmod ug+s /usr/bin/procmail

Resources