Sending mail via shell script - email

I want to send a zip file via email on shell script. I know I need to use the following command:
cat file.txt | mail -s "This is subject" [email]name#address.com[/email]
I always get this error:
line 13: mail: command not found
Does anyone know where and how I can install the mail command?
I am using Cygwin to test my shell script.

If you are in ubuntu, you can use apt
sudo apt-get install mailutils postfix

Install the "nail" or "mailx" package.

Related

cannot execute binary file centos?

I am using centos 6.9 and want to install xampp. But when I run the command on the terminal it showing error i.e. cannot execute binary file. So, How can I fix this problem and successfully install xampp ? Please help me.
chmod +x xampp-linux-x64-7.0.22-0-installer.run
./xampp-linux-x64-7.0.22-0-installer.run
after this command it showing
bash: ./xampp-linux-x64-7.0.22-0-installer.run: cannot execute binary file
You're probably running the install (binary) with a lesser privileged user. You'll have to use root user for modifying SELinux settings as such:
semanage fcontext -a -t httpd_sys_script_exec_t '/<install-location>(/.*)/?'
restorecon -R -v /<install-location>/

$ in zf not recognized in command

I have installed composer
When I want to test it by running $ composer serve from github.com/zendframework
I get error saying $ is not recotgnized
$ is not part of command. $ usage mean you are using user terminal.
Same with #, it mean you are using root terminal.
So, just type composer serve in your terminal.

Raspberry PI - Send mail from command line using GMAIL smtp server

How can I send email from Raspberry Pi using my gmail account?
I would like to send mail from command line and use this method in my scripts.
Envirenment:
Hardware: Raspberry PI 3
OS: Jessie
SMTP: smtp.gmail.com
I use this method on my Raspberry Pi 3 devices:
Google account setting
Login to your gmail account
Go to: Settings -> Accounts and Import -> Other Google Account settings
Go to: Personal info & privacy -> Account overview
Go to: Sign-in & security -> Connect apps & sites
Set option Allow less secure apps to ON
Install SSMTP
sudo apt-get install ssmtp
Save original conf file
sudo mv /etc/ssmtp/ssmtp.conf /etc/ssmtp/ssmtp.conf.bak
Create new conf file (with vi, or some other text editor)
sudo vi /etc/ssmtp/ssmtp.conf
file content
root=your_account#gmail.com
mailhub=smtp.gmail.com:587
FromLineOverride=YES
AuthUser=your_account#gmail.com
AuthPass=your_password
UseSTARTTLS=YES
UseTLS=YES
# Debug=Yes
Secure conf file
sudo groupadd ssmtp
sudo chown :ssmtp /etc/ssmtp/ssmtp.conf
If you have error on this step like ''cannot access'' ... you must find ssmtp file and use that path: sudo find / -name "ssmtp"
sudo chown :ssmtp /usr/sbin/ssmtp
sudo chmod 640 /etc/ssmtp/ssmtp.conf
sudo chmod g+s /usr/sbin/ssmtp
Sending mail from (only one) command line
echo "This is a test" | ssmtp recipient.address#some_domain.com
or
printf "To: recipient.address#some_domain.com\nFrom: RaspberryPi3\nSubject: Testing send mail from Raspberry\n\nThis is test. Best Regards!\n" | ssmtp -t
Sending mail from file test.txt
Make file with similar content:
To: recipient.address#some_domain.com
From: your_account#gmail.com
Subject: Testing send mail from Raspberry
This is test mail (body)
Best Regards!
Now you can send mail from file
ssmtp recipient.address#some_domain.com < test.txt
That's all :)

How to send data to command line after calling .sh file?

I want to install Anaconda through EasyBuild. EasyBuild is a software to manage software installation on clusters. Anaconda can be installed with sh Anaconda.sh.
However, after running I have to accept the License agreement and give the installation location on the command line by entering <Enter>, yes <Enter>, path/where/to/install/ <Enter>.
Because this has to be installed automatically I want to do the accepting of terms and giving the install location in one line. I tried to do it like this:
sh Anaconda.sh < <(echo) >/dev/null < <(echo yes) >/dev/null \
< <(echo /apps/software/Anaconda/1.8.0-Linux-x86_64/) > test.txt
From the test.txt I can read that the first echo works as <Enter>, but I can't figure out how to accept the License agreement, as it sees it now as not sending yes:
Do you approve the license terms? [yes|no]
[no] >>> The license agreement wasn't approved, aborting installation.
How can I send the yes correctly to the script input?
Edit: Sorry, I missed the part about having to enter more then one thing. You can take a look at writing expect scripts. thegeekstuff.com/2010/10/expect-examples. You may need to install it however.
You could try piping with the following command: yes yes | sh Anaconda.sh. Read the man pages for more information man yes.
Expect is a great way to go and probably the most error proof way. If you know all the questions I think you could do this by just writing a file with the answers in the correct order, one per line and piping it in.
That install script is huge so as long as you can verify you know all the questions you could give this a try.
In my simple tests it works.
I have a test script that looks like this:
#!/bin/sh
echo -n "Do you accept "
read ANS
echo $ANS
echo -n "Install path: "
read ANS
echo $ANS
and an answers file that looks like this:
Y
/usr
Running it like so works... perhaps it will work for your monster install file as well.
cat answers | ./test.sh
Do you accept Y
Install path: /usr
If that doesn't work then the script is likely flushing and you will have to use expect or pexpect.
Good luck!
Actually, I downloaded and looked at the anaconda install script. Looks like it takes command line arguments.
/bin/bash Anaconda-2.2.0-Linux-x86_64.sh -h
usage: Anaconda-2.2.0-Linux-x86_64.sh [options]
Installs Anaconda 2.2.0
-b run install in batch mode (without manual intervention),
it is expected the license terms are agreed upon
-f no error if install prefix already exists
-h print this help message and exit
-p PREFIX install prefix, defaults to /home/cody.stevens/anaconda
Use the -b and -p options...
so use it like so:
/bin/bash Anaconda-2.2.0-Linux-x86_64.sh -b -p /usr
Also of note.. that script explicitly says not to run with '.' or 'sh' but 'bash' so they must have some dependency on a feature of bash.
--
Cody

visudo nopasswd is not working for wget to execute shell_exec

I have added the below line in /etc/ visudo in the bottom before (Defaults passprompt="Password:" this line).
ALL=(root) NOPASSWD:/usr/bin/wget
When ever i try to with wget command, it is asking passowrd. I can download files after i use sudo command only. Can anyone help to download files without sudo command as I need to use the command in shell_exec PHP file.
The following works to give all users the right to execure /usr/bin/wget
ALL ALL=/usr/bin/wget, NOPASSWD: ALL
you can then use
sudo wget google.com
Without being asked for a password