batch
, atq, atrm queue, examine or delete jobs for later execution
see also :
atq - atrm - atd - cron - nice - sh
Synopsis
at
[-V] [-q queue] [-f file]
[-mMlv] timespec...
at [-V] [-q queue] [-f
file] [-mMkv] [-t time]
at -c job [job...]
atq [-V] [-q queue]
at [-rd] job [job...]
atrm [-V] job [job...]
batch
at -b
add an example, a script, a trick and tips
examples
source
Looking for utility to batch change created/modified date of multiple files in ascending datetime (windows XP/7/Mac/Linux)
Good Question although maybe Flickr should have any option for
ordering the uploaded files.
For Windows i would suggest
Nirsoft Bulk File Changer
For Linux one could easily write a bash script and utilize the
touch command to change multiple files.
The touch command is also available on Mac OS X, someone has
written an automation task to do this but again this could be
done on the terminal
FILES=./*
for f in $FILES
do
echo "Processing $f file..."
touch $f
done
This bash script will touch every file in ascending order. You
could add a "sleep" to the script if you wanted each file to have
a different second value.
user@computer:/tmp/data$ ls -l
total 9028
-rw-r--r-- 1 user user 428800 Apr 19 12:18 File1
-rw-r--r-- 1 user user 4338800 Apr 19 12:18 File2
-rw-r--r-- 1 user user 4438800 Apr 19 12:18 File3
-rwxrwxrwx 1 user user 78 Apr 19 12:18 fix.sh
source
Batch converting PNG to JPG in linux
Your best bet would be to use Imagemagick
I am not an expert in the actual usage, but I know you can pretty
much do anything image related with this!
An example is:
convert image.png image.jpg
and it will keep the original as well as creating the converted
image. As for batch. I think you need to use the Mogrify tool
(from the same command line when in imagemagick). Keep in mind
that this overwrites the old images.
The command is:
mogrify -format jpg *.png
source
How to auto detect text file encoding?
Try the chardet
Python
module.
(2012-04-18: Website appears to be dead. It's still on
Github and
archive.org, though.)
source
How to list all 'at' jobs without root privileges?
This may not be the answer you want, but strictly speaking, you
could boot a Live CD and use that to look at the files in
/var/spool/at (or equivalent).
The privacy and security provisions of Unix/Linux does not allow
you to do what you want. The at files are stored by default with
"other" read privilege set to off.
source
how to copy I/O not just redirect (Windows and Linux)
tee
call calabash -D sim.xpl 2>&1 | tee test.txt
source
Batch video presenting (playing, pausing, going to specific time, ...) in Linux
I would use a playlist in VLC. It supports some special commands
like start, stop and pause.
Like this example:
#EXTM3U
#EXTINF:,Video title 1
#EXTVLCOPT:start-time=0
#EXTVLCOPT:stop-time=25
Video_filename1.wmv
vlc://pause:10
#EXTINF:,Video title 1
#EXTVLCOPT:start-time=25
#EXTVLCOPT:stop-time=35
Video_filename1.mp3
#EXTINF:,Another movie
#EXTVLCOPT:start-time=35
#EXTVLCOPT:stop-time=120
Anothermovie.avi
Paste into a m3u-file and play with VLC.
This would play the first 25 secs of Video_filename1.wmv, pause
for 10 secs, play 10 secs more and then jump to Anothermovie.avi
at 35 secs into the move and the play 2 minutes.
source
Linux command line tool to batch rename MP3 files based on ID3 tag info, or give random name if no ID3 info present
id3v2
and some scripting should make this possible.
I'll look through the man pages and try to write up an example,
but id3v2 -l file
will list the tags from that file.
From there you can pipe through awk/sed/whatever to end up with a
command to rename the file.
source
How to bulk-rename files with invalid encoding or bulk-replace invalid encoded characters?
You're going to run in some problems if you want to rename files
and directories at the same time. Renaming just a file
is easy enough. But you want to make sure the directories are
also renamed. You can't simply mv Motörhead/Encöding
Motorhead/Encoding
since Motorhead
won't
exist at the time of the call.
So, we need a depth first traversal of all files and folders, and
then rename the current file or folder only. The following works
with GNU find
and Bash 4.2.42 on my OS X:
#!/usr/bin/env bash
find "$1" -depth -print0 | while read -r -d '' file; do
d=$( dirname "$file" )
f=$( basename "$file" )
new=${f//[^a-zA-Z0-9\/\._\-]/}
if [ "$f" != "$new" ] # if equal, name is already clean, so leave alone
then
if [ -e "$d/$new" ]
then
echo "Notice: \"$new\" and \"$f\" both exist in "$d":"
ls -ld "$d/$new" "$d/$f"
else
echo mv "$file" "$d/$new" # remove "echo" to actually rename things
fi
fi
done
Save this script as rename.sh
, make it executable
with chmod +x rename.sh
. Then, call it like
rename.sh /some/path
. Resolve any file name
collisions (“Notice
” announcements).
If you're absolutely sure it does the right
replacements, remove the echo
from the script to
actually rename things instead of just printing what it does.
To be safe, I'd recommend testing this on a small subset of files
first.
Options explained
To explain what goes on here:
-
-depth
will ensure directories are recursed
depth-first, so we can "roll up" everything from the end.
Usually, find
traverses differently (but not
breadth-first).
-
-print0
ensures the find
output is
null-delimited, so we can read it with read -d ''
into the file
variable. Doing so helps us deal
with all kinds of weird file names, including ones with spaces,
and even newlines.
- We'll get the directory of the file with
dirname
. Don't forget to always quote your variables
properly, otherwise any path with spaces or globbing characters
would break this script.
- We'll get the actual filename (or directory name) with
basename
.
- Then, we remove any invalid character from
$f
using Bash's string replacement capabilities. Invalid means
anything that's not a lower- or uppercase letter, a digit, a
slash (\/
), a dot (\.
), an underscore,
or a minus-hyphen.
- If
$f
is already clean (the cleaned name is
identical to the current name), skip it.
- If
$new
already exists in directory
$d
(e.g., you have files named resume
and résumé
in the same directory), issue a warning.
You don't want to rename it, because, on some systems, mv
foo foo
causes a problem. Otherwise,
- We finally rename the original file (or directory) to its new
name
Since this will only act on the deepest hierarchy, renaming
Motörhead/Encöding
to
Motorhead/Encoding
is done in two steps:
-
mv Motörhead/Encöding Motörhead/Encoding
-
mv Motörhead Motorhead
This ensures all replacements are done in the correct order.
Example files and test run
Let's assume some files in a base folder called
test
:
test
test/Motörhead
test/Motörhead/anöther_file.mp3
test/Motörhead/Encöding
test/Randöm
test/Täst
test/Täst/Töst
test/with space
test/with-hyphen.txt
test/work
test/work/resume
test/work/résumé
test/work/schedule
Here is the output from a run in debug mode (with the
echo
in front of the mv
), i.e., the
commands that would be called, and the collision warnings:
mv test/Motörhead/anöther_file.mp3 test/Motörhead/another_file.mp3
mv test/Motörhead/Encöding test/Motörhead/Encoding
mv test/Motörhead test/Motorhead
mv test/Randöm test/Random
mv test/Täst/Töst test/Täst/Tost
mv test/Täst test/Tast
mv test/with space test/withspace
Notice: "resume" and "résumé" both exist in test/work:
-rw-r—r-- … … test/work/resume
-rw-r—r-- … … test/work/résumé
Notice the absence of messages for with-hyphen.txt
,
schedule
, and test
itself.
source
Is there a way to save "work sessions" in linux
There's no way to save multiple sessions per se, but you can
write shell scripts that start multiple apps in the background.
$ mkdir ~/bin
$ cat > ~/bin/session1
#!/bin/sh
firefox &
gedit &
nautilus somedir &
<Ctrl-D>
$ chmod +x ~/bin/session1
$ session1
Creating a launcher on a panel is left as an exercise for the
reader.
source
ssh and execute interactive command
You need to allocate a pseudo-tty to your ssh session for the
srun
command.
Try this:
ssh -t my_machine "srun --pty r"
source
How to bulk-rename files with invalid encoding or bulk-replace invalid encoded characters?
You're going to run in some problems if you want to rename files
and directories at the same time. Renaming just a file
is easy enough. But you want to make sure the directories are
also renamed. You can't simply mv Motörhead/Encöding
Motorhead/Encoding
since Motorhead
won't
exist at the time of the call.
So, we need a depth first traversal of all files and folders, and
then rename the current file or folder only. The following works
with GNU find
and Bash 4.2.42 on my OS X:
#!/usr/bin/env bash
find "$1" -depth -print0 | while IFS= read -r -d '' file; do
d="$( dirname "$file" )"
f="$( basename "$file" )"
new="${f//[^a-zA-Z0-9\/\._\-]/}"
if [ "$f" != "$new" ] # if equal, name is already clean, so leave alone
then
if [ -e "$d/$new" ]
then
echo "Notice: \"$new\" and \"$f\" both exist in "$d":"
ls -ld "$d/$new" "$d/$f"
else
echo mv "$file" "$d/$new" # remove "echo" to actually rename things
fi
fi
done
Save this script as rename.sh
, make it executable
with chmod +x rename.sh
. Then, call it like
rename.sh /some/path
. Resolve any file name
collisions (“Notice
” announcements).
If you're absolutely sure it does the right
replacements, remove the echo
from the script to
actually rename things instead of just printing what it does.
To be safe, I'd recommend testing this on a small subset of files
first.
Options explained
To explain what goes on here:
-
-depth
will ensure directories are recursed
depth-first, so we can "roll up" everything from the end.
Usually, find
traverses differently (but not
breadth-first).
-
-print0
ensures the find
output is
null-delimited, so we can read it with read -d ''
into the file
variable. Doing so helps us deal
with all kinds of weird file names, including ones with spaces,
and even newlines.
- We'll get the directory of the file with
dirname
. Don't forget to always quote your variables
properly, otherwise any path with spaces or globbing characters
would break this script.
- We'll get the actual filename (or directory name) with
basename
.
- Then, we remove any invalid character from
$f
using Bash's string replacement capabilities. Invalid means
anything that's not a lower- or uppercase letter, a digit, a
slash (\/
), a dot (\.
), an underscore,
or a minus-hyphen.
- If
$f
is already clean (the cleaned name is
identical to the current name), skip it.
- If
$new
already exists in directory
$d
(e.g., you have files named resume
and résumé
in the same directory), issue a warning.
You don't want to rename it, because, on some systems, mv
foo foo
causes a problem. Otherwise,
- We finally rename the original file (or directory) to its new
name
Since this will only act on the deepest hierarchy, renaming
Motörhead/Encöding
to
Motorhead/Encoding
is done in two steps:
-
mv Motörhead/Encöding Motörhead/Encoding
-
mv Motörhead Motorhead
This ensures all replacements are done in the correct order.
Example files and test run
Let's assume some files in a base folder called
test
:
test
test/Motörhead
test/Motörhead/anöther_file.mp3
test/Motörhead/Encöding
test/Randöm
test/Täst
test/Täst/Töst
test/with space
test/with-hyphen.txt
test/work
test/work/resume
test/work/résumé
test/work/schedule
Here is the output from a run in debug mode (with the
echo
in front of the mv
), i.e., the
commands that would be called, and the collision warnings:
mv test/Motörhead/anöther_file.mp3 test/Motörhead/another_file.mp3
mv test/Motörhead/Encöding test/Motörhead/Encoding
mv test/Motörhead test/Motorhead
mv test/Randöm test/Random
mv test/Täst/Töst test/Täst/Tost
mv test/Täst test/Tast
mv test/with space test/withspace
Notice: "resume" and "résumé" both exist in test/work:
-rw-r—r-- … … test/work/resume
-rw-r—r-- … … test/work/résumé
Notice the absence of messages for with-hyphen.txt
,
schedule
, and test
itself.
source
Auto-rotate rotated images with mogrify
I was googling 'Rotated image' and similar terms. Though when I
formulated the last question, "How can I edit my script to
preserve the orientation?", it came to me and googled for
'orientation'. Since the full question was already finished and
it can help someone out there, I answer it.
The solution came from this forum.
Same instructions: Put this in a text file, give it execution
permissions, double click and run (in terminal) for converting
all JPGs from that folder into pngs.
#! /bin/bash
echo "Converting JPG to png. Please don't close this window."
mogrify -alpha on -auto-orient -format png *.JPG
mogrify -alpha on -auto-orient -format -alpha on png *.jpg
Here is the finished working script and a screenshot to show it
source
Batch scan a lot of pictures
Apparently the scanimage
program
has batch scanning built in, so no scriping is required:
scanimage --format=tiff --batch "/path/to/scanned_image-%d.tiff" --batch-prompt
"The --batch options provide the features
for scanning documents using document feeders."
"--batch [format] is used to specify the
format of the filename that each page will be written to."
"--batch-prompt will ask for pressing
RETURN before scanning a page. This can be used for scanning
multiple pages without an automatic document feeder."
See the man page for more info.
source
How to batch process every image in a pdf using commandline tools?
you can try to use inkscape in command line
inkscape -S # show all the object inside the document
inkscape --select=YouImage --verb=YourTransformation
inkscape --verb-list #to obtain all the possibilities
Or you can extract image, modify them with anything you want
(imagemagick?) then replace them in your document with inkscape.
Regards
description
at and
batch read commands from standard input or a
specified file which are to be executed at a later time,
using /bin/sh.
at
executes commands at a specified time.
atq
lists the user’s pending jobs, unless the user is
the superuser; in that case, everybody’s jobs are
listed. The format of the output lines (one for each job)
is: Job number, date, hour, queue, and username.
atrm
deletes jobs, identified by their job number.
batch
executes commands when system load levels permit; in
other words, when the load average drops below 1.5, or the
value specified in the invocation of atd.
At
allows fairly complex time specifications, extending the
POSIX.2 standard. It accepts times of the form HH:MM
to run a job at a specific time of day. (If that time is
already past, the next day is assumed.) You may also specify
midnight, noon, or teatime (4pm) and you can
have a time-of-day suffixed with AM or PM for
running in the morning or the evening. You can also say what
day the job will be run, by giving a date in the form
month-name day with an optional year, or
giving a date of the form MMDD[CC]YY,
MM/DD/[CC]YY,
DD.MM.[CC]YY or
[CC]YY-MM-DD. The specification
of a date must follow the specification of the time
of day. You can also give times like now + count
time-units, where the time-units can be minutes,
hours, days, or weeks and you can tell at
to run the job today by suffixing the time with today
and to run the job tomorrow by suffixing the time with
tomorrow.
For example, to
run a job at 4pm three days from now, you would do at 4pm
+ 3 days, to run a job at 10:00am on July 31, you would
do at 10am Jul 31 and to run a job at 1am tomorrow,
you would do at 1am tomorrow.
The definition
of the time specification can be found in
/usr/share/doc/at/timespec.
For both
at and batch, commands are read from standard
input or the file specified with the -f option and
executed. The working directory, the environment (except for
the variables BASH_VERSINFO, DISPLAY,
EUID, GROUPS, SHELLOPTS, TERM,
UID, and _) and the umask are retained from
the time of invocation.
As at is
currently implemented as a setuid program, other environment
variables (e.g. LD_LIBRARY_PATH or LD_PRELOAD)
are also not exported. This may change in the future. As a
workaround, set these variables explicitly in your job.
An at
- or batch - command invoked from a
su(1) shell will retain the current userid. The user
will be mailed standard error and standard output from his
commands, if any. Mail will be sent using the command
/usr/sbin/sendmail. If at is executed from a
su(1) shell, the owner of the login shell will
receive the mail.
The superuser
may use these commands in any case. For other users,
permission to use at is determined by the files
/etc/at.allow and /etc/at.deny. See
at.allow(5) for details.
options
-V
prints the version number to
standard error and exit successfully.
-q
queue
uses the specified queue. A
queue designation consists of a single letter; valid queue
designations range from a to z and A to
Z. The a queue is the default for at
and the b queue for batch. Queues with higher
letters run with increased niceness. The special queue
"=" is reserved for jobs which are currently
running.
If a job is
submitted to a queue designated with an uppercase letter,
the job is treated as if it were submitted to batch at the
time of the job. Once the time is reached, the batch
processing rules with respect to load average apply. If
atq is given a specific queue, it will only show jobs
pending in that queue.
-m
Send mail to the user when the job has completed even if
there was no output.
-M
Never send mail to the user.
-f file
Reads the job from file rather than standard
input.
-t time
run the job at time, given in the format
[[CC]YY]MMDDhhmm[.ss]
-l
Is an alias for atq.
-r
Is an alias for atrm.
-d
Is an alias for atrm.
-b
is an alias for batch.
-v
Shows the time the job will be executed before reading
the job.
Times displayed
will be in the format "Thu Feb 20 14:50:00
1997".
-c
cats the jobs listed on the
command line to standard output.
files
/var/spool/cron/atjobs
/var/spool/cron/atspool
/proc/loadavg
/var/run/utmp
/etc/at.allow
/etc/at.deny
bugs
The correct
operation of batch for Linux depends on the presence
of a proc- type directory mounted on
/proc.
If the file
/var/run/utmp is not available or corrupted, or if
the user is not logged on at the time at is invoked,
the mail is sent to the userid found in the environment
variable LOGNAME. If that is undefined or empty, the
current userid is assumed.
At and
batch as presently implemented are not suitable when
users are competing for resources. If this is the case for
your site, you might want to consider another batch system,
such as nqs.
see also
at.allow,
at.deny, atd , cron ,
nice , sh , umask.
author
At was mostly
written by Thomas Koenig, ig25[:at:]rz[:dot:]uni-karlsruhe.de.