Disk clean up script_error - linux

I am new to scripting and learning and i written a script as shown below to clear all logs under the path /usr/apache/logs
#!/bin/bash
path="/usr/apache/logs/"
for i in $(find $path . -name "*log*");do
cat /dev/null > $i;
done
And after running above script i got the below Output error
/usr/apache/logs/
find: `./lost+found': Permission denied
find: `./root': Permission denied
l_clear.sh: line 4: /usr/apache/logs/: Is a directory
l_clear.sh: line 4: ./Backup/Clients/work_catalog: Is a directory
please help me why i got "find: `./lost+found': Permission denied" even i specified the logs path.

change to root user and
execute your script with root permission.
if use debian:
$ sudo su
# bash your_script.sh
if you use fedora:
$ su -
# bash your_script.sh

Related

Shell script Execute file in tmp directory

I am trying to execute shell script which i have created in tmp folder.
i have granted permission as well to the script using command below.
chmod a+x tmp/test/test.sh
when i run the code i get permission denied error.
[root#server test]# ./test.sh
-bash: ./test.sh: Permission denied
The issue may cause by tmp is noexec, and you can use the sh command to execute the the shell script
sh ./test.sh
Try this workaround:
(. tmp/test/test.sh)

Tomcat not starting in linux ---permission denied to run startup.sh

I pasted tomcat folder in Linux machine. User is root . When I go to bin folder and execute ./startup.sh I'm getting an error:permission denied. [This is what I got]
How to rectify this issue.
give:
chmod -R 777 startup.sh
Then error will come as:Cannot find ./catalina.sh
then give:
chmod -R 777 catalina.sh
Tomcat will start.
the problem was because there was no permission for executing. u can see if permission is there or not by giving:
ls -l
As color of file name is white, I suppose file is not executable; try the following command
ls -l
It gives you file list with its permission. Try using command
chmod a+x startup.sh
If still permission denied. Try
sudo chmod a+x startup.sh
Then try using
./startup.sh
If still permission denied. Then try
sudo ./startup.sh
Hope it will be helpful.
Verify, that your filesystem with the new tomcat folder isn't mounted with "noexec". Please run a "ls -l", "file start.sh" and a "head start.sh" .
Tom
It is also worthwhile to check which bash you are using with
which bash
This is because you might see the error
Cannot find ./catalina.sh
when your bash is /usr/bin/bash but is working perfectly fine when bash is /usr/bash

why do I get “permission denied” when trying to start tomcat and write std out to a text file?

I'm trying to start tomcat in such a way that it writes standard out to a text file.
I'm do this but I get a permission denied. Why is that?
[rob#machine1 bin]$ pwd
/usr/lib64/apache-tomcat-6.0.36/bin
[rob#machine1 bin]$ sudo ./startup.sh > console.log 2<&1
bash: console.log: Permission denied
Redirections are done by the current shell, which does not have sudo rights. When you want to write to console.log, you run sudo on a shell that can in turn do redirections:
sudo sh -c './startup.sh > console.log 2>&1'
Remarks:
I switched the direction of 2<&1 into 2>&1.
You might want to include the redirections in your own startup script.

LINUX Permission issues

Can anyone help me in fixing the permission issues in Linux.
I am new to Linux and i am trying to run a script called buildAll.sh
by moving to that specific directory and i typed ./buildAll.sh the response i got was
./buildAll.sh: 16: ./buildAll.sh: ./buildJS.sh: Permission denied
i tried to run using sudo ./buildAll.sh , but that didn't work.
Then i tried with chmod -r 777 buildAll.sh and again i tried to run that script but no change.
I have a folder called build which has some dependency can be seen a folder with locked picture.
Can anyone help me to run the script without having the permission issues please
in line 16 your script seems to call buildJS.sh and the permissions OF THAT seem to be incorrect
You obviously have a pervasive permissions problem. Why don't you just start again, unpack the files into a new directory without using sudo or su, and then use chmod +x on the files that need to be executable?
sudo chmod +x buildAll.sh
Should do the trick
It seems by the error message the issue is with buildJS.sh. If buildJS.sh is not in your current directory (it might not be as buildAll.sh might be changing directories), find buildJS.sh and then:
chmod +x ${directory_where_found}/buildJS.sh
Since .sh files should have executable permissions by default you can do this:
cd $YOUR_DIRECTORY
find . -name '*.sh' -exec chmod +x {} \;
I tried with sudo chmod +x buildAll.sh
rm: cannot remove ‘build’: Permission denied
cp: cannot stat ‘./build/.svn’: Permission denied
cp: cannot stat ‘./build/compiler.jar’: Permission denied
cp: cannot stat ‘./build/buildJS.sh’: Permission denied
touch: setting times of ‘build’: Permission denied
./buildAll.sh: line 14: cd: build: Permission denied
./buildAll.sh: line 16: ./buildJS.sh: No such file or directory
You have given permission only to run your script. However, this doesn't mean that you have permission for all of instructions launched by the script. The error message is there to prove it ;) .

Permission denied for root shrc

Whenever I open the terminal on my Centos5.1, I always get this error
/root/.cshrc Permission denied
and then I can't use networking commands (ip,ifconfig,...) because they are reported as unknown commands.
Verify that you have permissions to read .cshrc To do that issue:
ls -l /root/.cshrc
If the output begins with to dashes it means that you don't. To give yourself read permission to this file issue:
chmod +r /root/.cshrc
Now if you run ls -l /root/.cshrc the output should start with -r.

Resources