/dev/null No such file or directory - osx-elcapitan

I run El Capitan OS X and am trying to use /dev/null however when I do anything with it, for example ls:
ls -l /dev/null
ls: /dev/null: No such file or directory
I've also tried:
sudo mknod -m 666 /dev/null c 1 3
However that outputs the following:
mknod: illegal option -- m
usage: mknod [-F format] name [b | c] major minor
mknod [-F format] name [b | c] major unit subunit
mknod name [b | c] number
mknod name w
How can I fix this?

I was able to use the answer provided from this question along with the question itself. The fix for this issue is as follows:
sudo -s << _EOF
mknod /dev/null c 3 2
chmod 666 /dev/null
_EOF

Related

How to make ssh-add read passphrase from a varible?

I want to load ssh key protected by passphrase from varible with ssh-add.
When I try to load it from file works well like this.
eval $(ssh-agent)
DISPLAY=1 SSH_ASKPASS="passwordfile" ssh-add id_rsa < /dev/null
Now I want to assign passphrase and the id_rsa to variables and use something like this:
eval $(ssh-agent)
DISPLAY=1 SSH_ASKPASS="$PASSPHRASE" ssh-add $ID_RSA < /dev/null
How I could achieve this?
The SSH_ASKPASS variable stores an executable, so you can specify a one-line script that simply outputs the value of the password variable:
Contents of ~/.ssh/askpass.sh (must be set to executable, e.g. chmod +x ~/.ssh/askpass.sh)
#!/bin/sh
echo "$PASSPHRASE"
Then you can run:
$ SSH_ASKPASS_REQUIRE=force SSH_ASKPASS="$HOME/.ssh/askpass.sh" ssh-add "$ID_RSA"
Full example:
$ export PASSPHRASE="test123" ID_RSA="$HOME/.ssh/test.rsa"
$ ssh-keygen -t rsa -b 4096 -o -a 100 -f "$ID_RSA"
Generating public/private rsa key pair.
Enter passphrase (empty fоr no passphrase): test123
Enter same passphrase again: test123
Your identification has been saved iո test.rsa
Your public key has been saved iո test.rsa.pub
The key fingerprint is:
SHA256:dLo1pYfzd33lb+GiI8QcES5jaLHEmNhrvRJiMWR3d58 adamhotep#tabasco
The key’s randomart image is:
+---[RSA 4096]----+
|.oo.++ . o. |
|.+.+o.= o.. . |
| o o+ +..oE. |
| o +....o+ + |
|. o . . S B . .|
| . . * = oo|
| . o . o *|
| . . o o+|
| ..o ...|
+----[SHA256]-----+
$ printf '#!/bin/sh\necho "$PASSPHRASE"\n' > ~/.ssh/askpass.sh
$ chmod +x ~/.ssh/askpass.sh
$ eval $(ssh-agent -s)
$ SSH_ASKPASS_REQUIRE=force SSH_ASKPASS="$HOME/.ssh/askpass.sh" ssh-add "$ID_RSA"
Identity added: test.rsa (adamhotep#tabasco)
(See also my ssh-keygen advice for why those extra arguments increase security.)

Count number of files in directory then scp transfer a certain range such as 21404-42806

I found the number of files in /dev/shm/split/1/ to be 42806 using:
/bin/ls -lU /dev/shm/split/1/ | wc -l
What I can't seem to find anywhere online is how to select a certain range, say from 21404-42806, and use scp to securely copy those files. Then, for management purposes, I would like to move the files I copied to another folder, say /dev/shm/split/2/.
How do I do that using CentOS?
I tried:
sudo chmod 400 ~/emails/name.pem ; ls -1 /dev/shm/split/1/ | sed -n '21443,42806p' | xargs -i scp -i ~/emails/name.pem {} root#ipaddress:/dev/shm/split/2/
This produced:
no such file or directory
errors on all of the files...
ls itself lists files relative to the directory you give. This means your ls prints the filenames in the directory, but later on, scp doesn't have the path to them. You can fix this two ways:
Give the path to scp:
ls -1 /dev/shm/split/1/ | sed -n '21443,42806p' | xargs -i \
scp -i ~/emails/name.pem /dev/shm/split/1/{} root#ipaddress:/dev/shm/split/2/
Change to that directory and it will work:
cd /dev/shm/split/1/; ls -1 | sed -n '21443,42806p' | xargs -i \
scp -i ~/emails/name.pem {} root#ipaddress:/dev/shm/split/2/

Use qdel to delete all my jobs at once, not one at a time

This is a rather simple question but I haven't been able to find an answer.
I have a large number of jobs running in a cluster (>20) and I'd like to delete them all and start over.
According to this site I should be able to just do:
qdel -u netid
to get rid of them all, but in my case that returns:
qdel: invalid option -- 'u'
usage: qdel [{ -a | -c | -p | -t | -W delay | -m message}] [<JOBID>[<JOBID>]|'all'|'ALL']...
-a -c, -m, -p, -t, and -W are mutually exclusive
which obviously indicates that the command does not work.
Just to check, I did:
qstat -u <username>
and I do get a list of all my jobs, but:
qdel -u <username>
also fails.
Found the answer buried in an old supercluster.org thread:
qselect -u <username> | xargs qdel
Worked flawlessly.
Building on what Gabriel answered:
qselect -u <username> | xargs qdel
qselect -u <username> -s <state> | xargs qdel
<state> would be R for running jobs only.
qselect will allow you to select job based on other criterias, like ressources asked (-l), destination queue (-q) ...
qdel -u <username>
will only work with SGE
sometimes a simple grep/cut can help too:
qstat | grep $USER | cut -d. -f1 | xargs qdel
This way we can also grep on a particular keyword for the jobs and delete them.
HTH
Try
$ qdel {id1..id2}
So for example:
$ qdel {1148613..1148650}
For UGE:
qstat -u | gawk '{print $1}' | xargs qdel
# Delete all jobs owned by the current user.
#
# Command breakdown:
# ------------------
#
# qselect
# -u selects all jobs that belong to the current user
# -s EHQRTW selects all job states except for Complete
#
# xargs
# --no-run-if-empty Do not run qdel if the result set is empty
# to avoid triggering a usage error.
#
# qdel
# -a delete jobs asynchronously
#
# The backslashes are a trick to avoid matching any shell aliases.
\qselect -u $(whoami) -s EHQRTW | \xargs --no-run-if-empty \qdel -a
Another possibility is to do qdel all. It deletes all jobs from everyone. When you don't have access for other people's job, it deletes only your jobs.
It is not the most beautiful solution, but it is surely the shortest!
qstat | cut -d. -f1 | sed "s; \(.*\) 0;qdel \1;" | bash
sed's power.
Just use the following command:
qdel all
It will cancel all jobs running on cluster.

How to hide cat errors?

( find -print0 | xargs -0 cat ) | wc -l (from How to count all the lines of code in a directory recursively?) prints the total number of lines in all files in all subdirectories. But it also prints a bunch of lines like cat: ./x: Is a directory.
I tried ( find -print0 | xargs -0 cat ) | wc -l &> /dev/null (and also 2> /dev/null and > /dev/null 2>&1) but the messages are still printed to the shell.
Is it not possible to hide this output?
( find -type f -print0 | xargs -0 cat ) | wc -l overcomes this problem, but I'm still curious why redirecting stderr doesn't work, and if there is a more general purpose way to hide errors from cat.
You need to redirect the stderr stream of the cat command to /dev/null. What you have done is redirected the stderr stream of wc. Try this:
( find -print0 | xargs -0 cat 2>/dev/null ) | wc -l
If you want find only to find “regular” files, you must use find -type f ….
By the way, if you want to calculate lines of code, you should take a look at ohcount.

tput: unknown terminal

I'm on AIX-6.1 and I'm trying to make use of tput inside my $PS1.
I've confirmed I can't even run tput from the commandline. Following is my session:
# tput
unknown terminal "xterm"
# echo $TERM
xterm
# tput -T ansi
unknown terminal "ansi"
In fact, ...
# ls /usr/lib/terminfo/x
x1700 xl83 xterm+pcc3 xterm+pcfkeys xterm-88color xterm-hp xterm-old xterm-vi
x1720 xtalk xterm+pcf0 xterm+pcfn xterm-8bit xterm-ic xterm-r5 xterm-vt220
x1750 xterm xterm+pcf1 xterm-16color xterm-basic xterm-mono xterm-r6 xterm-vt52
x820 xterm+pcc0 xterm+pcf2 xterm-24 xterm-bold xterm-new xterm-rep xterm-xfree86
xdku xterm+pcc1 xterm+pcf3 xterm-256color xterm-boldso xterm-noapp xterm-sco xterm-xmc
xitex xterm+pcc2 xterm+pcfN xterm-65 xterm-color xterm-nrc xterm-sun xterms
# ls /usr/lib/terminfo/x | wc -l
48
# for term in $(ls /usr/lib/terminfo/x) ; do tput -T $term ; done 2>&1 | grep 'unknown terminal' | wc -l
48
# for term in $(ls /usr/lib/terminfo/x) ; do TERM=$term tput ; done 2>&1 | grep 'unknown terminal' | wc -l
48
Any ideas? Thanks in advance.
Is your TERMINFO variable set? Without it, I believe the system won't find your terminfo files. Or perhaps it is set incorrectly?
If you're running sh, ksh, bash or similar, try:
export TERMINFO=/usr/lib/terminfo
If you're not sure what shell you're using (I'm pretty sure you do, but others might read this too), type:
echo $SHELL
If you're using csh, tcsh or similar, then you should instead type:
setenv TERMINFO /usr/lib/terminfo
After that, try running tput again.
I fixed this in Mac OS Catalina with,
export TERMINFO=/usr/share/terminfo