Bash: No such file or directory? - linux

I try to use an executable script (wkhtmltopdf) on a Linux shared webserver (Debian, 64bit). I am pretty sure that I compiled everything correct, but whenever I want to execute the file I get as an response :
> ./wkhtmltopdf -H
-bash: ./wkhtmltopdf: No such file or directory
To be sure that the file is there, here the ls output :
> ls
wkhtmltoimage wkhtmltopdf
Furthermore I tested the file command on it, which outputs the following :
> file wkhtmltopdf
wkhtmltopdf: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped
My question is now :
Why does bash tells me that there is no 'file or directory', when there obviously is one?
My first guess would be that the shared server does not allow to execute binary files? But shouldn't it then be a problem of permissions, with a different bash output?
Edit :
> id
uid=2725674(p8907906) gid=600(ftpusers) groups=600(ftpusers)
> ls -l wkhtmltopdf
-rwxrwxrwx 1 p8907906 ftpusers 39745960 Jan 20 09:33 wkhtmltopdf
> ls -ld
drwx---r-x 2 p8907906 ftpusers 44 Jan 28 21:02 .

I bet you miss dynamic linker. Just do a
readelf --all ./wkhtmltopdf | grep interpreter
You should get an output like this:
[Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]
There are high chances that you system lacks the interpreter (/lib64/ld-linux-x86-64.so.2 in the example). In this case bash would yell No such file or directory, just like when the binary itself is missing.
You can try to use a different linker. Sometime you can succeed. Just do a:
/path/to/the/linker /path/to/your/executable
This command:
find /lib* -name ld-linux\*
will help you find the linkers on your system. Or you can do the readelf command on some command that does run. It will show you correct, working linker.
OR, since you are running Debian system, just do a
sudo apt-get install wkhtmltopdf
to install native version of the tool :)

In my case
$ readelf --all ./wkhtmltopdf | grep interpreter # readelf: Displays information about ELF files.
[Requesting program interpreter: /lib/ld-linux.so.2]
On a machine where the executable was working:
$ ls -lah /lib/ld-linux.so.2
lrwxrwxrwx 1 root root 25 Apr 16 2018 /lib/ld-linux.so.2 -> i386-linux-gnu/ld-2.27.so
$ dpkg -S /lib/ld-linux.so.2 # -S, --search filename-search-pattern: Search for a filename from installed packages.
libc6:i386: /lib/ld-linux.so.2
So to fix the problem (reference)
sudo dpkg --add-architecture i386
sudo apt update
sudo apt install libc6:i386 # GNU C Library: Shared libraries (from apt show)

Missing the linker was my case as well. I could fix it with the help of nsilent22 answer like this:
readelf --all /usr/local/myprogram | grep interpreter
[Requesting program interpreter: /lib64/ld-lsb-x86-64.so.3]
But that linker did not exist anymore.
The old situation in /lib64 was:
ld-linux-x86-64.so.2 -> /lib/x86_64-linux-gnu/ld-2.31.so
ld-linux-x86-64.so.3 -> ld-linux-x86-64.so.2
So it turned out this was just a symlink to the systems' linker.
Moving over to /lib64 , which itself is a symlink to usr/lib64 and creating a symlink over there did not work. I assume that there are to many symbolic link levels after Debian moved everything into /usr
However creating a 'direct' symlink
ln -s /usr/lib64/ld-linux-x86-64.so.2 /lib64/ld-lsb-x86-64.so.3
did the job; /usr/lib64 now shows:
ld-linux-x86-64.so.2 -> /lib/x86_64-linux-gnu/ld-2.31.so
ld-lsb-x86-64.so.3 -> /usr/lib64/ld-linux-x86-64.so.2

I ran into this issue on my raspberry pi 4 running aarch64 alpine 3.13. Using the answer provided by #vkersten, I was able to determine that I was missing /lib/ld-linux-aarch64.so.1.
I resolved this by installing gcompat with apk add gcompat.

Related

Where would I find the kernel .config file in Linux ubuntu?

I'm copying my kernel config file from an existing system to the kernel tree, and I entered this command:
/boot/config$(uname -r)
Yet I got:
bash: /boot/config-5.15.0-46-generic: Permission denied
Does anyone know why its saying permission denied and how to fix? I am using Ubuntu in VirtualBox.
As #Tsyvarev mentioned in comments it is possible that you're trying to execute file, that have no exec permissions:
$ ls -l /boot
...
-rw-r--r-- 1 root root 217414 Aug 20 2021 config-5.4.0-rc1+
...
Try to run: cat /boot/config-$(uname -r) to read the config file for currently running kernel.

rpm provides shared object that is also required by a provided executable

Preface: Auto dependencies (AutoReqProv) is ON
As the title says, we have a shared object that is provided by the RPM package we have built, so it is placed in the %files section of the spec file. However, we have executable files in the %files section as well, that are dependent on this .so. So, with auto dependencies on, it is trying to resolve this issue during install of this package. Obviously, this .so has not been installed yet on the target system because it is apart of the package being installed. So, it throws an install error.
Has anyone experienced this issue before? Auto dependencies being on is a requirement for this, so removing it is a last ditch effort.
**Edit: Here is the %files section of my spec file. The .so in question is located in /usr/local/%{name}
%files
%defattr(-,root,root)
/usr/local/%{name}
/usr/bin/*
/etc/ld.so.conf.d/*
/etc/opt/aubit4gl2
/usr/lib/*
%attr(0755, -, -) /usr/local/bin/c4glpg
%attr(0755, -, -) /usr/local/bin/c4glpg2
The error is this:
error: Failed dependencies:
libaubit4gl.so is needed by aubit4gl2-10.0.4-2.i686
Edit 2: Here is the install section of the rpmbuild command output
make[1]: Leaving directory `/home/bhand/rpmbuild/BUILD/aubit4gl2-10.0.4/aubit4gl2'
+ cp -a aubit4gl2/atomix4pg/sqldist /home/bhand/rpmbuild/BUILDROOT/aubit4gl2-10.0.4-2.i386/usr/local/aubit4gl2/atomix4pg
+ cp -a aubit4gl2/etc/aubitrc /home/bhand/rpmbuild/BUILDROOT/aubit4gl2-10.0.4-2.i386/etc/opt/aubit4gl2
+ sed -i 's/^AUBITETC=.*/AUBITETC=\/etc\/opt\/aubit4gl2/g' /home/bhand/rpmbuild/BUILDROOT/aubit4gl2-10.0.4-2.i386/etc/opt/aubit4gl2/aubitrc
+ sed -i 's/^AUBITDIR=.*/AUBITDIR=\/usr\/local\/aubit4gl2/g' /home/bhand/rpmbuild/BUILDROOT/aubit4gl2-10.0.4-2.i386/etc/opt/aubit4gl2/aubitrc
+ sed -i 's/^AUBITDIR_SRC=.*/AUBITDIR_SRC=\/usr\/local\/aubit4gl2/g' /home/bhand/rpmbuild/BUILDROOT/aubit4gl2-10.0.4-2.i386/etc/opt/aubit4gl2/aubitrc
+ echo '# NOBLE: Make aubit utils only create 32-bit output'
+ echo CFLAGS=-m32
+ ln -s /usr/local/aubit4gl2/lib/libaubit4gl.so /home/bhand/rpmbuild/BUILDROOT/aubit4gl2-10.0.4-2.i386/usr/lib/libaubit4gl.so
+ ln -s /usr/local/aubit4gl2/atomix4pg/bin/c4glpg /home/bhand/rpmbuild/BUILDROOT/aubit4gl2-10.0.4-2.i386/usr/local/bin/c4glpg
+ ln -s /usr/local/aubit4gl2/atomix4pg/bin/c4glpg2 /home/bhand/rpmbuild/BUILDROOT/aubit4gl2-10.0.4-2.i386/usr/local/bin/c4glpg2
+ ln -s /usr/local/aubit4gl2/bin/amake /home/bhand/rpmbuild/BUILDROOT/aubit4gl2-10.0.4-2.i386/usr/bin/amake
+ ln -s /usr/local/aubit4gl2/bin/aubit /home/bhand/rpmbuild/BUILDROOT/aubit4gl2-10.0.4-2.i386/usr/bin/aubit
+ ln -s /usr/local/aubit4gl2/bin/aubit-config /home/bhand/rpmbuild/BUILDROOT/aubit4gl2-10.0.4-2.i386/usr/bin/aubit-config
Processing files: aubit4gl2-10.0.4-2.i686
warning: Explicit %attr() mode not applicaple to symlink: /home/bhand/rpmbuild/BUILDROOT/aubit4gl2-10.0.4-2.i386/usr/local/bin/c4glpg
warning: Explicit %attr() mode not applicaple to symlink: /home/bhand/rpmbuild/BUILDROOT/aubit4gl2-10.0.4-2.i386/usr/local/bin/c4glpg2
Provides: libA4GL_HTML.so libA4GL_file.so libA4GL_memcache.so libA4GL_pcre.so libA4GL_pick.so libA4GL_roman.so libA4GL_string.so libDATA_module.so libDATA_module_definition.so libDATA_report.so libDATA_struct_form.so libEXREPORT_NOPDF.so libFORM_GENERIC.so libFORM_NOFORM.so libFORM_XDR.so libHELP_std.so libLEX_C.so libLEX_CS.so libLEX_EC.so libLEX_PERL.so libLEX_WRITE.so libLOGREPPROC_CSV.so libLOGREPPROC_HTML.so libLOGREPPROC_TXT.so libLOGREP_CSV.so libLOGREP_HTML.so libLOGREP_TXT.so libMSG_NATIVE.so libPACKER_FORMXML.so libPACKER_GZPACKED.so libPACKER_MEMPACKED.so libPACKER_PACKED.so libPACKER_PERL.so libPACKER_XDR.so libPACKER_XML.so libRPC_NORPC.so libRPC_XDR.so libSQLPARSE_INFORMIX.so libSQLPARSE_NONE.so libSQL_FILESCHEMA.so libSQL_nosql.so libSQL_unixodbc.so libUI_CONSOLE.so libUI_HL_GTK.so libUI_HL_TUI.so libUI_HL_TUIN.so libUI_TUI.so libUI_TUI_wide.so libUI_XML.so libXDRPACKER_module.so libXDRPACKER_module_definition.so libXDRPACKER_report.so libXDRPACKER_struct_form.so libaubit4gl-1.2_39.so libbarcode.so libchannel.so liberrhook_sample.so aubit4gl2 = 10.0.4-2 aubit4gl2(x86-32) = 10.0.4-2 perl(report) perl(using)
Requires(interp): /bin/sh /bin/sh /bin/sh
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
Requires(pre): /bin/sh
Requires(post): /bin/sh
Requires(postun): /bin/sh
Requires: /bin/sh /usr/bin/perl libatk-1.0.so.0 libaubit4gl-1.2_39.so libaubit4gl.so libc.so.6 libc.so.6(GLIBC_2.0) libc.so.6(GLIBC_2.1) libc.so.6(GLIBC_2.1.3) libc.so.6(GLIBC_2.12) libc.so.6(GLIBC_2.2) libc.so.6(GLIBC_2.2.3) libc.so.6(GLIBC_2.3) libc.so.6(GLIBC_2.7) libcairo.so.2 libcurl.so.4 libdl.so.2 libdl.so.2(GLIBC_2.0) libdl.so.2(GLIBC_2.1) libfontconfig.so.1 libform.so.5 libformw.so.5 libfreetype.so.6 libgdk-x11-2.0.so.0 libgdk_pixbuf-2.0.so.0 libgio-2.0.so.0 libglib-2.0.so.0 libgobject-2.0.so.0 libgtk-x11-2.0.so.0 libm.so.6 libm.so.6(GLIBC_2.0) libncurses.so.5 libncursesw.so.5 libodbc.so.2 libpanel.so.5 libpanelw.so.5 libpango-1.0.so.0 libpangocairo-1.0.so.0 libpangoft2-1.0.so.0 libpcre.so.1 libpthread.so.0 libpthread.so.0(GLIBC_2.0) libtinfo.so.5 libz.so.1 perl(DBI) perl(Date::Calc) perl(strict) perl(using) rtld(GNU_HASH)
Processing files: libaubit4gl-1.2_39-2.i686
Provides: libaubit4gl = 1.2_39-2 libaubit4gl(x86-32) = 1.2_39-2 libaubit4gl-1.2_39.so
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
Requires: libc.so.6 libc.so.6(GLIBC_2.0) libc.so.6(GLIBC_2.1) libc.so.6(GLIBC_2.1.3) libc.so.6(GLIBC_2.3) libc.so.6(GLIBC_2.7) libcurl.so.4 libdl.so.2 libdl.so.2(GLIBC_2.0) libdl.so.2(GLIBC_2.1) libm.so.6 libm.so.6(GLIBC_2.0) libz.so.1 rtld(GNU_HASH)
Checking for unpackaged file(s): /usr/lib/rpm/check-files /home/bhand/rpmbuild/BUILDROOT/aubit4gl2-10.0.4-2.i386
Wrote: /home/bhand/rpmbuild/SRPMS/aubit4gl2-10.0.4-2.src.rpm
Wrote: /home/bhand/rpmbuild/RPMS/i686/aubit4gl2-10.0.4-2.i686.rpm
Wrote: /home/bhand/rpmbuild/RPMS/i686/libaubit4gl-1.2_39-2.i686.rpm
Executing(%clean): /bin/sh -e /home/bhand/rpmbuild/tmp/rpm-tmp.wtiBPg
+ umask 022
+ cd /home/bhand/rpmbuild/BUILD
+ cd aubit4gl2-10.0.4
+ rm -rf /home/bhand/rpmbuild/BUILDROOT/aubit4gl2-10.0.4-2.i386
+ exit 0
cp ~/rpmbuild/RPMS/i686/aubit4gl2-10.0.4-2.i686.rpm aubit4gl2-10.0.4-2.centos.7.postgres.i686.rpm
cp ~/rpmbuild/RPMS/i686/libaubit4gl-1.2_39-2.i686.rpm libaubit4gl-1.2_39-2.i686.rpm
cp RELEASENOTES aubit4gl2-10.0.4-2.centos.7.postgres.i686.RELEASENOTES
Edit 3: The output of rpm -qlvp aubit4gl2-10.0.4-2.centos.7.postgres.i686.rpm
rpm -qlvp nscaubit4gl2-10.0.4-2.centos.7.postgres.i686.rpm | grep libaubit4gl
lrwxrwxrwx 1 root root 42 Oct 11 14:06 /usr/lib/libaubit4gl.so -> /usr/local/nscaubit4gl2/lib/libaubit4gl.so
-rwxr-xr-x 1 root root 2439297 Oct 11 14:06 /usr/local/nscaubit4gl2/lib/libaubit4gl-1.2_39.so
lrwxrwxrwx 1 root root 21 Oct 11 14:06 /usr/local/nscaubit4gl2/lib/libaubit4gl.so -> libaubit4gl-1.2_39.so
Make sure the library has the executable bits on.
I added "Provides: libaubit4gl.so" to my spec file and it works now. For some reason, RPM was saying that the aubit4gl package was not providing this .so.
I'm still not 100% on why that is. But, this is what solved my problem.
If any file in the package's %files list is a shared library, the library's SONAME is automatically added to the list of capabilities the package provides.
In my case SONAME for the shared library is empty. After setting SONAME for shared library(as below using -Wl option in gcc) packging the modified shared library worked fine (automatically resolved capabilities).
To test whether SONAME is set properly you can use command objdump -p libaubit4gl.so | grep SONAME
SONAME is assigned/embedded into shared library during linking as below
gcc -shared -fPIC -Wl,-soname,libaubit4gl.so -o libaubit4gl.so foo.o bar.o baz.o -lc
SONAME can be different from file name libaubit4gl.so.
(Note: This is not as per standard but suggesting this to get rid of your error. However if you want to name shared library as per standards see versioning a shared library
You could have your spec file create two .rpm files: a libaubit4gl one and a aubit4gl one. The first provides this library and the other one requires it.
At least, this seems kind of good practice to me, at least if the library can be used w/o the binary.
I was having a similar problem. I was setting the executable bits on the created library with %file %attr, but it turned out that I wasn't setting the executable bits in my %install phase.
Setting the shared library file to 755 during %install AND %files fixed the problem.
I'm guessing that rpmbuild looks at the files in the BUILD directory for its analysis, so they have to be correct there, not just after the "rpm -i" installation.

How can I check if ncurses is installed?

How can I check if ncurses is installed in a Red-Hat Linux OS? One solution is to use
dpkg -l '*ncurses*' | grep '^ii'
But I don't even have the dpkg package in my system, and since I don't have the administrative rights, I can't install it.
On RedHat based systems there is (mostly) no dpkg but you can use rpm -qa | grep ncurse
on mac:
prompt> ls -la /usr/include/ncurses.h
lrwxr-xr-x 1 root wheel 8 11 jul 14:24 /usr/include/ncurses.h -> curses.h
The second line being not empty, this means ncurses is installed.

Without admin prevlieges, how do I find the directories searched by ld?

How do I find the directories searched in by the GNU linker, without admin privileges?
I can get the listing in the following way:
$ sudo ldconfig -v 2>/dev/null | grep -v ^$'\t'
/lib/i386-linux-gnu:
/usr/lib/i386-linux-gnu:
/usr/local/lib:
/lib/x86_64-linux-gnu:
/usr/lib/x86_64-linux-gnu:
/usr/lib/fglrx:
/usr/lib32/fglrx:
/lib32:
/usr/lib32:
/lib:
/usr/lib:
/usr/lib/i386-linux-gnu/sse2: (hwcap: 0x0000000004000000)
this solution came from: How to print the ld(linker) search path
However, on a machine where I do not have admin privileges, this will not work. I assume that’s because ldconfig is located in /sbin/. I download glibc and installed it locally to create another version of ldconfig. I guess that was silly though because the local version gives me:
/usr/local/lib:
/usr/local/lib64:
Is it still possible to get all the directories as a non-admin?
There doesn't appear to be any helpful ld flags, or environment variables to do the job.
Just because ldconfig is in sbin doesn't mean it can't be run as a normal user. Simply use that command and specify the full path to ldconfig:
/sbin/ldconfig -v 2>/dev/null | grep -v ^$'\t'

Why is my core file not overwritten?

On Ubuntu 12.04, open a new text file and write:
#include <stdlib.h>
int main()
{
abort();
return 0;
}
Now run:
g++ yourfile.cpp
Then run the executable, which will core dump:
./a.out
Now check the mtime of the file:
-rw-r----- 1 xxxxx xxxxx 228K 2012-10-01 19:20:20.752136399 -0500 core
Now run the executable again:
./a.out
Now check the mtime again:
-rw-r----- 1 xxxxx xxxxx 228K 2012-10-01 19:20:20.752136399 -0500 core
It's the same! Why doesn't a fresh core overwrite the old one? When rebuilding this causes gdb to complain the core is older than the executable.
Just to be sure it wasn't a permissioning problem, I tried this in a fresh directory in /tmp and ran chmod -R 777 **/* inside. Running the executable twice still didn't produce a new core O_o Also, ulimit -c reports 800000000, more than enough for a core this size.
I also tried running a clean bash with env - bash --noprofile --norc and still running the binary doesn't update the mtime of the core unless I delete it first.
If you refer to https://bugs.launchpad.net/ubuntu/+source/apport/+bug/160999 this is a bug in Ubuntu using O_EXCL to open the file, preventing it from overwriting an existing core.
The core(5) man page lists certain conditions under which a core file is not [re-]written. You probably meet one of those conditions. Please read carefully that man page.

Resources