Remove host name from sender description mailx - mailx

When I use this to send a mail I get the sender address as (root)<noreply#rediff.co.in> where root is the host name .
mailx -s 'Spammers `date -d "-1 days" +%Y-%m-%d`' mail_id1#gmail.com,mail_id2#gmail.com -- -r 'noreply#gmail.com'
Either I want to remove the host name completely in the sender description or specify another name.
Any help is appreciated.
Update:
I have also tried the same as mentioned by Rune in this question How set the From email address for mailx command? which doesn't seem to work.
mailx -s 'Spammers `date -d "-1 days" +%Y-%m-%d`' mail_id1#gmail.com,mail_id2#gmail.com -- -r 'noreply#gmail.com (Anonymous)'

This is what I had done to solve it. I just added -F 'Sender Name'
mailx -s 'Spammers `date -d "-1 days" +%Y-%m-%d`' mail_id1#gmail.com,mail_id2#gmail.com -- -F 'Spam Alert' -r 'noreply#gmail.com'

Related

Subscribe and Publish in BASH like a receive Buffer

I want to buffer all messages of a subscription during processing publish messages.
The reason is a firmware update over MQTT. I want to send data with crc and the microcontroller have to verify the content and need to answer with new address pointer.
For now, i got it working without any interaction from the microcontroller. If size doesn't fit, or mc is not online, my bash script sends all the data of the binary file into the nirvana.
If I publish a message and subscribe directly after the publish, it is possible to lose an answer very easily.
But I'm not so experienced with bash and I need some suggestions how to do this...
This is what I have:
mosquitto_pub -h $MQTT_SERVER -t "spiffs/${client_name}/file_info" -m "$binary_file" -p 8883 -i "fw_server" --cafile server-cert.pem -d --insecure -u $MQTT_USER -P $MQTT_PW
mosquitto_sub -h $MQTT_SERVER -p 8883 -t "+/${client_name}/#" -i "fw_server" --cafile server-cert.pem -d --insecure -u $MQTT_USER -P $MQTT_PW | while read -r payload
do
fp_jq_rspCode=".upload.fp" # file pointer
address=$(echo $payload | jq -r $fp_jq_rspCode)
echo "${payload}" | jq -c '.[]'
echo "address pointer:$address"
c=${address}
addr=$(printf '%08x' "$c")
content=$(xxd -p -c $payload_size -l $payload_size -seek $c $binary_file)
length=`expr length "$content"`
len=$(printf '%04x' "$length")
crc32=$(echo -n "$content" | gzip -c | tail -c8 | hexdump -n4 -e '"%u"')
crc32=$(printf '%08x' "$crc32")
echo "$addr $len $content $crc32"
message=$(printf '%08x%04x%s%s' "$c" "$length" "$content" "$crc32")
mosq=$(mosquitto_pub -h $MQTT_SERVER -t "spiffs/${client_name}/upload" -m "$message" -p 8883 -i "fw_server" --cafile server-cert.pem -d --insecure -u $MQTT_USER -P $MQTT_PW)
done

Sqlcmd: 'var=1': Invalid argument. using Bash Script

This is my first post in stackoverflow :D
I'm having a problem in passing variables in sql file using sqlcmd.
sqlcmd -S "$host" -U "$username" -P "$password" -d "$dbname" -s "║" -v test=1 -i $productQuery -h -1 | while IFS="," read -r row
do
# some stuff here..
done
It has error "Sqlcmd: 'test=1': Invalid argument. Enter '-?' for help.". Thanks in advance! :D
The |while ... is causing the error. I came up with different solution to solved my problem. Thanks to #user1934428

POST using Bash in Script

I am currently writing a script which gets a cookie and unique URL from a website, then uses that cookie and URL to post login/password information.
I am having trouble in getting this to work, some of the runs I have done gives me the message "switching from POST to GET" and I can't understand why.
Can someone please help me?
for i in $(cat accounts.txt); do
rm out.out
curl -L -b cookies.txt -c cookies.txt https://website.com | grep -Eo "(http|https)://cookies.website.com/idp[a-zA-Z0-9./?=_-]*" >> out.out
url=`head -1 out.out`
content="$(curl -X POST -L -v -b cookies.txt -d "$i" "$url" )"
echo "$url" "$i" "$content"
done

Using wget in shell trouble with variable that has \

I'm trying to run a script for pulling finance history from yahoo. Boris's answer from this thread
wget can't download yahoo finance data any more
works for me ~2 out of 3 times, but fails if the crumb returned from the cookie has a "\" character in it.
Code that sometimes works looks like this
#!usr/bin/sh
symbol=$1
today=$(date +%Y%m%d)
tomorrow=$(date --date='1 days' +%Y%m%d)
first_date=$(date -d "$2" '+%s')
last_date=$(date -d "$today" '+%s')
wget --no-check-certificate --save-cookies=cookie.txt https://finance.yahoo.com/quote/$symbol/?p=$symbol -O C:/trip/stocks/stocknamelist/crumb.store
crumb=$(grep 'root.*App' crumb.store | sed 's/,/\n/g' | grep CrumbStore | sed 's/"CrumbStore":{"crumb":"\(.*\)"}/\1/')
echo $crumb
fileloc=$"https://query1.finance.yahoo.com/v7/finance/download/$symbol?period1=$first_date&period2=$last_date&interval=1d&events=history&crumb=$crumb"
echo $fileloc
wget --no-check-certificate --load-cookies=cookie.txt $fileloc -O c:/trip/stocks/temphistory/hs$symbol.csv
rm cookie.txt crumb.store
But that doesn't seem to process in wget the way I intend either, as it seems to be interpreting as described here:
https://askubuntu.com/questions/758080/getting-scheme-missing-error-with-wget
Any suggestions on how to pass the $crumb variable into wget so that wget doesn't error out if $crumb has a "\" character in it?
Edited to show the full script. To clarify I've got cygwin installed with wget package. I call the script from cmd prompt as (example where the script above is named "stocknamedownload.sh, the stock symbol I'm downloading is "A" from the startdate 19800101)
c:\trip\stocks\StockNameList>bash stocknamedownload.sh A 19800101
This script seems to work fine - unless the crumb returned contains a "\" character in it.
The following implementation appears to work 100% of the time -- I'm unable to reproduce the claimed sporadic failures:
#!/usr/bin/env bash
set -o pipefail
symbol=$1
today=$(date +%Y%m%d)
tomorrow=$(date --date='1 days' +%Y%m%d)
first_date=$(date -d "$2" '+%s')
last_date=$(date -d "$today" '+%s')
# store complete webpage text in a variable
page_text=$(curl --fail --cookie-jar cookies \
"https://finance.yahoo.com/quote/$symbol/?p=$symbol") || exit
# extract the JSON used by JavaScript in the page
app_json=$(grep -e 'root.App.main = ' <<<"$page_text" \
| sed -e 's#^root.App.main = ##' \
-e 's#[;]$##') || exit
# use jq to extract the crumb from that JSON
crumb=$(jq -r \
'.context.dispatcher.stores.CrumbStore.crumb' \
<<<"$app_json" | tr -d '\r') || exit
# Perform our actual download
fileloc="https://query1.finance.yahoo.com/v7/finance/download/$symbol?period1=$first_date&period2=$last_date&interval=1d&events=history&crumb=$crumb"
curl --fail --cookie cookies "$fileloc" >"hs$symbol.csv"
Note that the tr -d '\r' is only necessary when using a native-Windows jq mixed with an otherwise native-Cygwin set of tools.
You are adding quotes to the value of the variable instead of quoting the expansion. You are also trying to use tools that don't know what JSON is to process JSON; use jq.
wget --no-check-certificate \
--save-cookies=cookie.txt \
"https://finance.yahoo.com/quote/$symbol/?p=$symbol" \
-O C:/trip/stocks/stocknamelist/crumb.store
# Something like thist; it's hard to reverse engineer the structure
# of crumb.store from your pipeline.
crumb=$(jq 'CrumbStore.crumb' crumb.store)
echo "$crumb"
fileloc="https://query1.finance.yahoo.com/v7/finance/download/$symbol?period1=$first_date&period2=$last_date&interval=1d&events=history&crumb=$crumb"
echo "$fileloc"
wget --no-check-certificate \
--load-cookies=cookie.txt "$fileloc" \
-O c:/trip/stocks/temphistory/hs$symbol.csv

Script to alert when Root Password Expiry in AIX

I am trying to build a script in AIX which I am planing to run as cron job.
I want the script to check if the root password will expire with in 10 days and trigger an email. I have written a script to trigger mail but I am not sure how to write a script for password expiry for root.
This is script for sending mail .
#!/bin/sh
sendmail -t -F 'ABC ' -f 'abc#xyz.com' << test.mail
From: ABC <abc#xyz.com>
To: def#xyz.com
Subject:
Password expired in 10 days
This script works fine .
But i want a script for AIX that will check root password expiry within 10 days of expiry date .
you can do it like,
lastupdate=lssec -f /etc/security/passwd -a lastupdate -s <username> | cut -d " " -f2 |cut -d "=" -f2
maxage=lsuser -a maxage itimadm | cut -d " " -f2 |cut -d "=" -f2
maxage=$(($maxage*7))
expires=$(($lastupdate+(60*60*24*$maxage)))
expire_date=perl -le 'print scalar localtime $expires
daysremaining=ceil((($expires - $now) / (60*60*24)) - 1)
echo $username,$maxage,$expire_date,$daysremaining
Though this is not full fledged script but logic is present (improvement is possible :) ) and you can add if clause for checking condition (daysremaining<10) then call your mailing script which will send mail to respective users.

Resources