bashdb startup error: bashdb/lib/setshow.sh: line 91: /dev/pts/2: Permission denied - linux

I'm trying to use bashdb on CentOS 4.1 (unfortunately I can't choose a different/newer OS).
I installed bash 4.2 then bashdb 4.2-0.8. THere were no complaints from configure, make, make checks, or make install: everything looked peachy.
But trying to use bashdb either as 'bash --debugger myscript' or 'bashdb myscript' always gets this error:
[bot#sjbld1 bin]$ bashdb -- putxen.sh
bash debugger, bashdb, release 4.2-0.8
Copyright 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Rocky Bernstein
This is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
/usr/local/share/bashdb/lib/setshow.sh: line 91: /dev/pts/2: Permission denied
/usr/local/share/bashdb/lib/setshow.sh: line 91: /dev/pts/2: Permission denied
/usr/local/share/bashdb/lib/setshow.sh: line 91: /dev/pts/2: Permission denied
/usr/local/share/bashdb/lib/setshow.sh: line 91: /dev/pts/2: Permission denied
[bot#sjbld1 bin]$
There's no line 91 in setshow.sh, and there's no /dev/pts in a directory listing of /dev.
Any suggestions how to proceed will be very much appreciated. I'm taking on a broken mess of shell script, and I'm not hot at bash (or Linux) and hope for more intimate debugging than set -x and echo statements.
Thanks
For completeness I should have added the bash script I was trying to use as bashdb test, as requested by konsolebox, though the "Permission denied" problem occurs with any code, and is solved by using sudo as suggested by Red Cricket. Here's the script:
[bot#sjcpbrvpxbld1 bin]$ cat putxen.sh
if [ x$1 == x ]
then
echo must have filename as parameter
exit 1
fi
if [ -e $1 ]
then
echo $1 found
else
echo cannot find ./$1
exit 1
fi
FTPTGT=10.10.10.25
DIRTGT=xva
echo ftp upload file to $DIRTGT directory on $FTPTGT
ftp -n $FTPTGT <<EOF
user anonymous pass
hash
bin
cd $DIRTGT
put "$1"
bye

Since programs often have stdout and stderr redirected, bashdb tries to write its output to a tty, unless directed otherwise; bashdb determines the console running the tty command.
Normally you don't need to run bashdb as root. But for reasons that are a mystery here, the user you are running bashdb as, is not able to write to the tty registered to it. That is:
echo hi > $(tty)
will probably give you the same "Permission denied". Probably ls -l $(tty) will tell you what's up there.
However, as suggested in the comments, you can workaround this by running as root such as via sudo: e.g.
sudo bashdb -- putxen.sh
Another workaround is to add your user to the group, e.g. tty that is listed when you run ls -l $(tty).

Related

GPIO access rights under Linux Debian buster in bash

sorry for the beginner's question, but I'm a bit stuck.
Debian Buster on an OrangePi Zero+
from root # echo "6" > /sys/class/gpio/export works fine as root
the same line in an bash script executed as root fails w/ Permission denied
The script is owner:root mod is 2777
From user Level $ sudo echo "6" > /sys/class/gpio/export fails as well
I need to execute this statement w/in a shell script (can be root)! so what can I do?
The culprit was found in CR/LF, imported from Windows. That's why it worked at cmd level and not in the script.

How do i fix bash error - /dev/tty No such device or address

As the question specifics ,i am getting this error while executing my bash script
In exact terms i get following error
bash: line 26: /dev/tty: No such device or address
bash: line 29: /dev/tty: No such device or address
Here are the concerned Line 26 and 29 in script respectively which causes the issue
read -e -p "Paste the links : " links </dev/tty
read -e -p "Enter your input : " sub </dev/tty
If someone wonders, i cannot simply remove writing to </dev/tty from line 26 and 29 , it causes different issues .. So basically i need fix or get alternative for writing to /dev/tty
I am executing my script by running -
curl raw_link | bash
Preferably i want a solution which only requires me to my edit my existing script .i don't want to run the script after saving it locally or execute it using any other way apart from curl raw_link | bash
ls -l /dev/tty returns the following
crw-rw-rw- 1 root root 5, 0 Aug 8 09:28 /dev/tty
ls -l </dev/tty returns the following
/bin/bash: /dev/tty: No such device or address
Also i would like to mention that this issue doesn't seem to be happening on every machine , i intend to use this script on Google Colab where i definitely do get this issue
To fix the bash error, you can try this workaround :
tty=$(readlink /proc/$$/fd/2)
read ... < $tty
$tty contains the actual tty device name.

Execute shell script whithin another script prompts: No such file or directory

(I'm new in shell script.)
I've been stuck with this issue for a while. I've tried different methods but without luck.
Description:
When my script attempt to run another script (SiebelMessageCreator.sh, which I don't own) it prompts:
-bash: ./SiebelMessageCreator.sh: No such file or directory
But the file exists and has execute permissions:
-rwxr-xr-x 1 owner ownergrp 322 Jun 11 2015 SiebelMessageCreator.sh
The code that is performing the script execution is:
(cd $ScriptPath; su -c './SiebelMessageCreator.sh' - owner; su -c 'nohup sh SiebelMessageSender.sh &' - owner;)
It's within a subshell because I first thought that it was throwing that message because my script was running in my home directory (When I run the script I'm root and I've moved to my non-root home directory to run the script because I can't move my script [ policies ] to the directory where the other script resides).
I've also tried with the sh SCRIPT.sh ./SCRIPT.sh. And changing the shebang from bash to ksh because the SiebelMessageCreator.sh has that shell.
The su -c 'sh SCRIPT.sh' - owner is necessary. If the script runs as root and not as owner it brokes something (?) (that's what my partners told me from their experience executing it as root). So I execute it as the owner.
Another thing that I've found in my research is that It can throw that message if it's a Symbolic link. I'm really not sure if the content of the script it's a symbolic link. Here it is:
#!/bin/ksh
BASEDIRROOT=/path/to/file/cpp-plwsutil-c
ore-runtime.jar (path changed on purpose for this question)
java -classpath $BASEDIRROOT com.hp.cpp.plwsutil.SiebelMessageCreator
exitCode=$?
echo "`date -u '+%Y-%m-%d %H:%M:%S %Z'` - Script execution finished with exit code $exitCode."
exit $exitCode
As you can see it's a very siple script that just call a .jar. But also I can't add it to my script [ policies ].
If I run the ./SiebelMessageCreator.sh manually it works just fine. But not with my script. I suppose that discards the x64 x32 bits issue that I've also found when I googled?
By the way, I'm automating some tasks, the ./SiebelMessageCreator.sh and nohup sh SiebelMessageSender.sh & are just the last steps.
Any ideas :( ?
did you try ?
. ./SiebelMessageCreator.sh
you can also perform which sh or which ksh, then modify the first line #!/bin/ksh

Bash Script works but not in when executed from crontab

I am new to linux and the script below is just an example of my issue:
I have a script which works as expected when I execute it however when I set it to run via crontab it doesn't work as expected because it doesn't read the file content into the variable.
I have a file 'test.txt' which has 'abc' in it. My script puts the text into a variable 'var' and then I echo it out to a log file:
var=$(</home/pi/MyScripts/test.txt)
echo "$var" >/home/pi/MyScripts/log.log
This works perfectly fine when I execute it and it echo's into the log file but not when I set it via crontab:
* * * * * /home/pi/MyScripts/test.sh
The cron job runs, and it sent me the following error message:
/bin/sh: 1: /home/pi/MyScripts/test.sh: Permission denied.
But I have given it 777 permissions:
-rwxrwxrwx 1 pi pi 25 Jun 10 15:31 test.txt
-rwxrwxrwx 1 pi pi 77 Jun 10 15:34 test.sh
Any ideas?
This happens when you run the script with a different shell. It's especially relevant for systems where /bin/sh is dash:
$ cat myscript
echo "$(< file)"
$ bash myscript
hello world
$ sh myscript
$
To fix it, add #!/bin/bash as the first line in your script.
Others have provided answers, but I will give you a big clue from your error message; emphasis mine:
/bin/sh: 1: /home/pi/MyScripts/test.sh: Permission denied.
Note how the cron job was trying to use /bin/sh to run the script. That’s solved by always indicating which shell you want to use at the top of your script like this.
#!/bin/bash
var=$(</home/pi/MyScripts/test.txt)
echo "$var" >/home/pi/MyScripts/log.log
If your script is using bash, then you must explicitly set /bin/bash in some way.
Also, regarding permissions you say this:
But I have given it 777 permissions:
First, 777 permissions is a massive security risk. If you do that it means that anyone or anything on the system can read, write & execute the file. Don’t do that. In the case of a cron job the only entity that needs 7 permissions on a file is the owner of the crontab running that file.
Meaning if this is your crontab, just change the permissions to 755 which allows others to read & execute but not write. Or maybe better yet change it to 700 so only you—as the owner of the file—can do anything to the file. But avoid 777 permissions if you want to keep your system safe, stable & sane.
You have two options. In the first line of your file, tell what program you want to interpret the script
#!/bin/bash
...more code...
Or in your crontab, tell what program you want to interpret the script
* * * * * bash /home/pi/MyScripts/test.sh
In this option, you do not need to make the script executable

/bin/bash giving a segmentation fault upon startup

I am getting a segmentation fault from bash when I try to SSH to a remote server (running RHEL 4.4.5-6). After providing my credentials, the SSH client spits back the "Last login: ..." information, and then just hangs.
Out of curiosity, I pressed Ctrl-C and was able to get to a bash prompt. However, it's not the "usual" prompt that I see (it usually has my username, the server hostname, etc).
login as: xxxxxxx
xxxxx#xxxx's password:
Last login: Fri Mar 30 14:33:41 2012 from xxx.xx.xx.xxx
-bash-4.1$ echo $0
-bash
-bash-4.1$
I tried to run /bin/bash from GDB. After a medium-sized wait time, I finally got a SIGSEGV error:
(gdb) run
Starting program: /bin/bash
Program received signal SIGSEGV, Segmentation fault.
0x08067ab5 in yyparse ()
(gdb)
The last (significant) changes that I've made to the system was installing GNU screen (using yum install screen). Screen seemed to hang as well when I tried to start it (I'm assuming because it tried running bash, and got the same segfault).
Edit:
I tried running rpm -V:
-bash-4.1$ rpm -V bash
-bash-4.1$
Here are my .bash* files:
.bashrc:
# .bashrc
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
.bash_profile:
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
.bash_logout:
# ~/.bash_logout
.bash_history is quite long. I erased it, tried logging in again, and got the same results.
You're recursively sourcing your .bashrc from inside itself, which in a short test here does indeed lead to a segmentation fault. Removing that part from your .bashrc should hopefully fix the problem.

Resources