Multiple cronjobs in a single crontab - unix

How do I cd into a directory and run a script in the same crontab? Currently I'm trying to do something like 32 11 19 1 * cd /Users/myusername/Documents && simple.py but when this runs I receive the error:
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=myusername>
X-Cron-Env: <USER=myusername>
X-Cron-Env: <HOME=/Users/myusername>
Date: Mon, 19 Jan 2015 11:32:00 -0500 (EST)
/bin/sh: simple.py: command not found
How can I fix this?

You must precede with ./ when executing the script from the current working directory.
32 11 19 1 * cd /Users/myusername/Documents && ./simple.py
I guess you script is a python script. /bin/sh: seems weird. If your script is a python script then add following line #!/usr/bin/env python if it does not already contain it.

Related

Difference in behavior between 2 aliased cds in unix shell

I connect to a remote computer thru VNC and use Konsole for my work. Konsole is version 2.3.3 using KDE 4.3.4. I have these two aliases:
alias ll 'ls -haltr; pwd'
alias cd 'cd \!*; ll'
which I observed to have the following behavior:
When path exists, it will cd to it and also do the ll alias
When path doesn't exist, it will simply say the path doesn't exist and won't do the ll anymore
Example:
Path exists
[10] % cd foo
total 14K
-rw-r----- 1 user group 913 Jun 3 2014 readme
-rw-r----- 1 user group 1.2K Dec 3 2020 report.txt
drwxr-x--- 2 user group 4.0K Jan 12 17:50 ./
drwx------ 77 user group 8.0K Jun 24 11:57 ../
/home/user/foo
[11] %
Path doesn't exist
[10] % cd nowhere
nowhere: No such file or directory.
[11] %
Now our department has transferred to another division and we've just started to connect remotely thru Exceed TurboX. I still use Konsole but the version is now 2.10.5 using KDE 4.10.5. I copied over the same two aliases, but I'm now observing a different behavior:
When path exists, it will cd to it and also do the ll alias (basically same as #1 above)
When path doesn't exist, it will attempt to cd AND still do the ll (different as #2 above)
So for #2, here's how it looks like:
[10] % cd nowhere
nowhere: No such file or directory.
total 120K
-rw-r----- 1 user group 272 Jan 6 2021 .cshrc
-rw-r----- 1 user group 1.2K Jan 6 2021 .alias
drwxr-x--- 2 user group 4.0K Jan 12 17:50 ./
drwx------ 77 user group 8.0K Jun 24 11:57 ../
/home/user
[11] %
I would like to know how to get behavior #2 of the previous working environment to this current working environment.
I've added the information on the Konsole and KDE versions because if the behavior is due to the version and there's no workaround, then I'll just be sad for the rest of my life working in this new remote desktop env. ^_^
I'm currently exploring a "check first if the path exists before doing ll" but to no avail. :'(
Edit:
The shell I'm using is tcsh
% printenv SHELL in both environments showed /bin/tcsh
And in addition:
Old environment
% echo $version
tcsh 6.17.00 (Astron) 2009-07-10 (x86_64-unknown-linux) options wide,nls,dl,al,kan,sm,rh,color,filec
New environment
% echo $version
3
The information in the question is still not sufficient to find out why tcsh behaves differently in the two working environments.
The alias defines a sequence of commands (cd followed by ll) without any condition.
alias cd 'cd \!*; ll'
On one system the execution of the alias seems to stop if the cd command reports an error for currently unknown reasons.
The correct way to prevent the execution of ll after a failed cd command would be the conditional execution of the ll command, e.g.
alias cd 'cd \!* && ll'
The decade long advice is: do not use aliases, use functions.
ll() { ls -haltr "$#" && pwd; }
cd() { cd "$#" && ll; }

Tmux does not work

I created many sessions in tmux and closed them all with one comand:
pkill -f tmux
Unfortunately, now when I create new session via
tmux new -s alex
And get the following error:
sessions should be nested with care, unset $TMUX to force
Tell me please how can I solve this problem?
This message indicates that you are still in a session attach.
For example, you can check:
salio#salios ~ % tmux ls
1: 1 windows (created Fri Jan 13 16:38:10 2023)
3: 1 windows (created Fri Jan 13 21:12:34 2023) (attached)
4: 1 windows (created Fri Jan 13 22:49:13 2023)
6: 2 windows (created Fri Jan 13 23:05:50 2023)
I am currently attached to session 3
If I run the following command, I get an error:
tmux attach-session -t <Favorite session>
sessions should be nested with care, unset $TMUX to force
So, first of this session, dis-attach with the command ‍Ctrl+b+d
Now use the following command:
tmux attach-session -t <Favorite session>

gpgv: keyblock resource `/root/rpmbuild/SOURCES/libguestfs.keyring': No such file or directory

ERROR:
[root#localhost SPECS]# rpmbuild -ba libguestfs.spec
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.xxzZTr
+ umask 022
+ cd /root/rpmbuild/BUILD
++ mktemp -d
+ tmphome=/tmp/tmp.BAJzdrk0ne
+ gpgv2 --homedir /tmp/tmp.BAJzdrk0ne --keyring
/root/rpmbuild/SOURCES/libguestfs.keyring /root/rpmbuild/SOURCES/libguestfs-
1.36.3.tar.gz.sig /root/rpmbuild/SOURCES/libguestfs-1.36.3.tar.gz
gpgv: keyblock resource `/root/rpmbuild/SOURCES/libguestfs.keyring': No such
file or directory
gpgv: Signature made Fri Mar 24 16:46:40 2017 EDT using RSA key ID E1B768A0
gpgv: Can't check signature: No public key
error: Bad exit status from /var/tmp/rpm-tmp.xxzZTr (%prep)
I do not have /root/rpmbuild/SOURCES/**libguestfs.keyring** file
and I want to know how it came?
Are you trying to build the RHEL 7.4 libguestfs package? The keyring file should be included in the source RPM. If you deleted it somehow then you can get it from the Fedora package here: https://src.fedoraproject.org/rpms/libguestfs/tree/master
You can also try the RHEL 7.5 preview packages (which include source) here: https://www.redhat.com/archives/libguestfs/2017-November/msg00006.html

unix list files with a full stop in name

I have 4 files: the naming convention is as follows:
hello.account.sub1.001
hello.account.sub2.001
hello.account.sub3.001
hello.account.sub4.001
If I use ls -l hello.account*001 to search files, no problem exists.
However, problem exists when using ls -l hello.account.*.001
The system complains that No such file or directory
I assume the system considers hello.account.*.001 is a single file.
This interests me so I ask: how can you search the file if a full stop is specified as searching criteria?
Many Thanks
Filename globbing is done by the shell, before actually executing the command (such as ls in your case). The following works:
$ ksh --version
version sh (AT&T Research) 93t+ 2010-06-21
$ ls -l hello.account.*.001
-rw-r--r-- 1 andreas users 0 Jul 22 03:59 hello.account.sub1.001
-rw-r--r-- 1 andreas users 0 Jul 22 03:59 hello.account.sub2.001
-rw-r--r-- 1 andreas users 0 Jul 22 03:59 hello.account.sub3.001
-rw-r--r-- 1 andreas users 0 Jul 22 03:59 hello.account.sub4.001
while the following does not:
$ ls -l "hello.account.*.001"
ls: hello.account.*.001: No such file or directory
The reason is that in the first case, the shell expands the file name pattern before executing ls - ls will then see four different file names passed as arguments.
In the second case, since the file name pattern is escaped with double quotes, ls gets the pattern itself passed (which ls does not further expand - it looks for a file with the name hello.account.*.001)

Listing JAR within WAR

jar -tvf hello.war
However, my .war also contains some .jar in a lib folder within the .war.
I need a command display the contents of all the .jars within the .war.
The reason I need command line and not use tools like Winrar is because I need to incorporate it in my UNIX shell script.
You can do this with a short script.
TEMPDIR=`mktemp -d`
REALPATH=`pwd`/$1
(cd $TEMPDIR && jar xf $REALPATH)
for j in `find $TEMPDIR -name "*.jar"`; do echo `basename $j`; jar tvf $j; done
rm -rf $TEMPDIR
E.G.
$ ./go.sh x.war
z.jar
0 Sat Jul 30 21:53:20 EST 2011 META-INF/
71 Sat Jul 30 21:53:20 EST 2011 META-INF/MANIFEST.MF
182 Sat Jul 30 21:52:54 EST 2011 go.sh
25 Sat Jul 30 21:50:46 EST 2011 zz.sh
x.jar
0 Sat Jul 30 21:33:28 EST 2011 META-INF/
71 Sat Jul 30 21:33:28 EST 2011 META-INF/MANIFEST.MF
0 Sat Jul 30 21:33:20 EST 2011 x
Not really useful in a shell script, but the easiest way I've found to do this when looking at webapps interactively is to open them in emacs; archive mode understands jars, and just needs to be told about .wars, by adding
(add-to-list 'auto-mode-alist '("\\.war\\'" . archive-mode)) to your .emacs. Then you can open the war like a normal directory, plus anything insde it:

Resources