How to get mutt delivery failed report in linux script - mutt

I use mutt command line to send mail from Linux environment, but I need to get the message while I give wrong email address, here is the command line:
mutt -e "my_hdr from:myName<myName#mail.com" -s "mail subject" wrongName#mail.com < text.txt
The wrongName#mail.com is not correct, but I have no idea how to get the message

Related

How to retrieve kubectl config value from Dex server configured with LDAP using curl command?

We have multiple Kubernetes clusters across our company. To get the kubectl config content we use Dex to login and copy/paste the content to our local confi for kubectl.
I want to make this automated and so run a bunch of command to get the content using curl.
I couldn't work out how by checking the requests responses. Please help me if anyone knows how.
I found how to do it. So we need to make two calls. First one retrieves the login page in which we can grab the request id:
the_id=$(curl -s -v -L "https://login.${cluster}" | grep -Po 'action="(.*)"')
The above searches in the response for attribute action= where it tells you where to submit the request
Then use the_id in the next call:
konfig=$(curl --insecure POST -H 'Content-Type: application/x-www-form-urlencoded' -d "login=$username&password=$password" -v -L "${cluster}${the_id}" | grep -Pzo '(?s)id=".*?</')
This command will return a HTML page in which you can find the config. Obviously for you it can be different response but fetching the request id from the first call is the key that I missed to begin with.

mosquitto_pub fails first try but then succeeds

I'm using the mosquitto library. Specifically, I'm running the following command...
mosquitto_pub --cafile rootCA.pem --cert deviceCertAndCACert.crt --key deviceCert.key -h <account>.iot.us-east-1.amazonaws.com -p 8883 -q 1 -t foo/bar -I anyclientID --tls-version tlsv1.2 -m 'Hello' -d
The first or second time I run the command, it always fails. After that, it runs successfully. I'm trying to put this in an automated script so I'd like it to run successfully the first time. Are there any flags that I can add to the command to ensure that it runs successfully the first time?
This is the error I get...
Client anyclientID6181 sending CONNECT
Error: The connection was lost.
Any help would be appreciated.

Shell Script stops after connecting to external server

I am in the process of trying to automate deployment to an AWS Server as a cool project to do for my coding course. I'm using ShellScript to automate different processes but when connecting to the AWS E2 Ubuntu server. When connected to the server, it will not do any other shell command until I close the connection. IS there any way to have it continue sending commands while being connected?
read -p "Enter Key Name: " KEYNAME
read -p "Enter Server IP With Dashes: " IPWITHD
chmod 400 $KEYNAME.pem
ssh -i "$KEYNAME.pem" ubuntu#ec2-$IPWITHD.us-east-2.compute.amazonaws.com
ANYTHING HERE AND BELOW WILL NOT RUN UNTIL SERVER IS DISCONNECTED
A couple of basic points:
A shell script is a sequential set of commands for the shell to execute. It runs a program, waits for it to exit, and then runs the next one.
The ssh program connects to the server and tells it what to do. Once it exits, you are no longer connected to the server.
The instructions that you put in after ssh will only run when ssh exits. Those commands will then run on your local machine instead of the server you are sshed into.
So what you want to do instead is to run ssh and tell it to run a set of steps on the server, and then exit.
Look at man ssh. It says:
ssh destination [command]
If a command is specified, it is executed on the remote host instead of a login shell
So, to run a command like echo hi, you use ssh like this:
ssh -i "$KEYNAME.pem" ubuntu#ec2-$IPWITHD.us-east-2.compute.amazonaws.com "echo hi"
Or, for longer commands, use a bash heredoc:
ssh -i "$KEYNAME.pem" ubuntu#ec2-$IPWITHD.us-east-2.compute.amazonaws.com <<EOF
echo "this will execute on the server"
echo "so will this"
cat /etc/os-release
EOF
Or, put all those commands in a separate script and pipe it to ssh:
cat commands-to-execute-remotely.sh | ssh -i "$KEYNAME.pem" ubuntu#ec2-$IPWITHD.us-east-2.compute.amazonaws.com
Definitely read What is the cleanest way to ssh and run multiple commands in Bash? and its answers.

curl email with attachment

I'am trying to send an E-mail with the following command via curl
curl smtp://smtp.live.com:25 -v --mail-from \"***#hotmail.com\" --mail-rcpt \"***#hotmail.com\" --ssl -u **#hotmail.com:*** -T \"oke\" -k --anyauth"
everything is working fine, I get the email. The only thing I want to change is, that the file "oke" is attached to the email. The command above sends me the data inside the email, but I want the file.
How can I attach the file to the email ?

Wireshark installed but not working on Amazon linux

I have installed the wireshark on amazon linux through the following command:
sudo yum install wireshark
The following commands gives me this output:
Package wireshark-1.8.10-25.22.amzn1.x86_64 already installed and latest version
But when i try to run wireshark command it gives the following error:
bash: wireshark: command not found
Am i missing something. Please note that i have access as root user. Any help is appreciated.
The wireshark command does not work. I resolved the issue by using the command below:
tshark -i eth0 -f "udp port 8080" -w captureFile.pcap
The following command captures the packets on eth0(interface name) with the filter on udp port number 8080 and then saves it to the file captureFile.pcap