pastebinit how to post pasties with login info? - linux

Not so many manuals for this package.
I want to post pasties to pastebin.com under my username. so
pastebinit -u myuser -p mypassword file.py
doesn't work, it's not logging in... why?

Try
$ pastebinit -u myuser -p mypassword -i file.py
Edit: Try a different host:
$ ./pastebinit -i file.py -b http://paste.ubuntu.com

Related

Redirecting linux terminal file data

I have two files. One is v3in.txt file in which I have the commands to be executed list. In the second file v3out.txt I wish to store the output of each of these commands.
Can some one help me how to use the standard input output stream to achieve this.
My v3in.txt file contents:
sudo snmpget -v 3 -l authPriv -a SHA -A "NetMan2019" -x DES -X "ITP201820" -u John 198.51.100.5 .1.3.6.1.2.1.1.4.0
sudo snmpget -v 3 -l authPriv -a SHA -A "Net20192020" -x DES -X "TCP201820" -u John 198.51.100.5 .1.3.6.1.2.1.1.5.0

How to store output of sudo -S su -c <user> <command> to any variable

I am trying to execute the following command but the output is not coming as required.
var=$(echo "<password>"|sudo -S su -l <user> -c "<command>")
Please help if anyone can?
Expected Result:
var=$(echo ""|sudo -S su -l -c "pwd")
echo $var /home/bhushan
$:
Actual Result:
echo $var
$:
You can use backticks
var=`sudo -S su -l -c ""`
or the $(command) syntax
var=$(sudo -S su -l -c "")
(keep in mind though that sudo -S su -l -c "" doesn't output anything so $var will be empty)
You can workaround it by storing the output of the command into a file, then change its permission so that all users will see it and in a following command load it from the file:
sudo -S "<command> > /tmp/sudocmd.out && chmod 644 /tmp/sudocmd.out"
var=$(cat /tmp/sudocmd.out)

Linux expect spawn can not find file

I wrote a expect script named load_data.exp
#!/usr/bin/expect
spawn "osm2pgsql -s -l -d postgres -W -U postgres -H localhost -P 5432 --hstore /absolute/path/to/bruges_belgium.osm"
expect "Password:" {send "mysecretpassword"}
change access by
chmod +x load_data.exp
run it by
./load_data.exp
the file definitely exits, it gives me error
spawn osm2pgsql -s -l -d postgres -W -U postgres -H localhost -P 5432 --hstore /absolute/path/to/bruges_belgium.osm
couldn't execute "osm2pgsql -s -l -d postgres -W -U postgres -H localhost -P 5432 --hstore /absolute/path/to/bruges_belgium.osm": no such file or directory
while executing
"spawn "osm2pgsql -s -l -d postgres -W -U postgres -H localhost -P 5432 --hstore /absolute/path/to/bruges_belgium.osm""
(file "./load_data.exp" line 6)
osm2pgsql is installed and can be run directly in terminal the following sentence
osm2pgsql -s -l -d postgres -W -U postgres -H localhost -P 5432 --hstore /absolute/path/to/bruges_belgium.osm
so there is a problem with spawn, I guess
As the error suggests, it's trying to find a program not called osm2pgsql, but one called osm2pgsql -s -l -d postgres -W -U postgres -H localhost -P 5432 --hstore /absolute/path/to/bruges_belgium.osm including all the spaces and dashes as part of the executable name. Remove the quotes from the spawn command:
spawn osm2pgsql -s -l -d postgres -W -U postgres -H localhost -P 5432 --hstore /absolute/path/to/bruges_belgium.osm
Try specifying absolute path to osm2pgsql (acquired by command 'which osm2pgsql')

What is the OS X equivalent of "useradd -r -d /opt/otrs/ -c 'OTRS user' otrs" and "usermod -G nogroup otrs www-data"

I am trying to install otrs on a mac. I am wondering what is the OS X equivalent of the following commands?
useradd -r -d /opt/otrs/ -c 'OTRS user' otrs
usermod -G nogroup otrs www-data
The following link might be helpful: http://www.maclife.com/article/columns/terminal_101_creating_new_users
And this script gives further information and examples: http://wiki.freegeek.org/index.php/Mac_OSX_adduser_script
According to that, the following commands should do it:
dscl . create /Users/otrs
dscl . create /Users/otrs RealName "OTRS user"
dscl . create /Users/otrs NFSHomeDirectory /opt/otrs
dseditgroup -o edit -t user -a otrs nogroup
dseditgroup -o edit -t user -a otrs otrs
dseditgroup -o edit -t user -a otrs www-data

How to use tee with sshpass in shell script

I have a situation that I need to append several lines(ip and hosts) from a file to /etc/hosts.
If I execute the below command
sshpass -p password cat /tmp/hosts |sudo tee -a /etc/hosts
I am getting
sudo: no tty present and no askpass program specified.
Sorry, try again.
sudo: no tty present and no askpass program specified. Sorry, try again.
sudo: no tty present and no askpass program specified. Sorry, try again.
sudo: 3 incorrect password attempts
Any alternatives to this?
How about
sudo -S sh -c 'cat /tmp/hosts >> /etc/hosts' <<< "password"
It's best to contain redirections for sudo within a subshell so that the elevated permissions are applied to opening the destination file.
ref: See https://stackoverflow.com/a/4327123/7552
The error you face comes from the fact that sshpass tries to send the password to cat, not to sudo. Your command line should have, in theory, looked rather like this:
cat /tmp/hosts |sshpass -p password sudo tee -a /etc/hosts
but sshpass does not forward stdin to sudo so this is a dead end. (sudo does forward stdin though that is why something like sudo tee works)
You could do something like this
sshpass -p password sudo echo "Hello"
cat /tmp/hosts | sudo tee -a /etc/hosts
so that the second call to sudo does not require a password.
Another option is to embed the cat and the redirection in a shell script and then just
sshpass -p password sudo ./thescript.sh
Or you can, as #glennjackman wrote, embed the cat and the redirection in a subshell:
sshpass -p password sudo sh -c 'cat /tmp/hosts >> /etc/hosts'
And of course, you can configure sudo to not require passwords.

Resources