I am not sure if this belongs to superuser. Please excuse.
Here is what I am trying to do. I need to create a ksh script which will establish an ssh connection to a remote machine and find all ".tar" files in a particular path for a particular date and list them. Next, I will need to perform an scp command to copy all those .tar files to the server I am executing the ksh script on.
Here is what I have so far and it is far from complete... (please bear with me.. I am very new to ksh scripting).
Can someone please advise if I am going in the right direction and provide some pointers as to how I can improve and achieve what I am trying to do?
Many thanks in advance.
SSERVER=server1
SOURCEPATH=/tmp/test
sudo ssh $SSERVER \
find $SOURCEPATH -name "*.tar" -mtime +7 -exec ls {} \;
#will the above two statements work?
#I then need to output the ls results to a temp variable (i believe) and issue an scp on each of the files
#Copy files from SOURCEPATH to PATH
sudo scp "$SSERVER:$SOURCEPATH/$file1" /tftpboot
sudo scp "$SSERVER:$SOURCEPATH/$file2" /tftpboot
SSERVER=server1
SOURCEPATH=/tmp/test
sudo ssh "$SSERVER" "find $SOURCEPATH -name '*.tar' -mtime +7" |
while IFS= read -r; do
sudo scp "$SSERVER:'$REPLY'" /tftpboot
done
Related
I tried to use this command line in Windows:
My goal is to find all the directories in root#xx.xx.xx.xx:/var/log/ for a specific port and download them locally.
For the find command, I am excluding all folders which include this name "logFolder".
set outputPath=C:\MyDestination
scp -P 22 -r 'find root#xx.xx.xx.xx:/var/log/ -type d \( ! -name logFolder \)` %outputPath%
I downloaded mongoDB and I try to use brew, it didn't work.
I try bunch of commands such as:
$ curl -O https://fastdl.mongodb.org/osx/mongodb-osx-x86_64-3.4.6.tgz
$ tar -zxvf mongodb-osx-x86_64-3.4.6.tgz
$ mkdir -p mongodb
$ cp -R -n mongodb-osx-x86_64-3.4.6/ mongodb
$ sudo mv mongodb /usr/local
Didn't work
Step 5: it says the directory is not empty or is not exist. I try to empty the directory didn't work and I try to create a different one, it didn't work.
I can't find any solution. Can someone help me, please?
I think your /usr/local folder already contains a non-empty folder named mongodb.
Refer this for details.
You can confirm it by listing out the files in it
ls /usr/local/mongodb
Maybe, you can try removing that directory as a superuser if it doesn't have any important files and continue with the installation
I used centos 6.5
in / path I have a lot of files that started with this name tmp_
I work with a user franco who has a limit permission ( and I can't add permission to this user )
and with FileZilla when I try to delete these files, I have a permission denied message.
so the solution is to delete these files with command in putty tool
because in putty, I can use command like this sudo rm .....
but I did not find the exact command.
I found this kind of command :
rm ./-tmp_
I want only to delete the files which are only in \ path and not in its subdirectories and which started with tmp_
I work with critical system so I want to be sure before execute any command.
To find target files use :
This will just print files on console.
find / -maxdepth 1 -type f -name 'tmp_*'
To remove files (not directories):
find / -maxdepth 1 -type f -name 'tmp_*' -exec rm -f {} \;
Please use -maxdepth attribute if you want to target files to specific depth.
The command "sudo rm -rf /tmp_" is worked if the /tmp_ directory not used for you.
xx#xx-PC ~/xampp/htdocs/sites
$ rmdir /s "yo-2"
rmdir: `/s': No such file or directory
rmdir: `yo-2': Directory not empty
xx#xx-PC ~/xampp/htdocs/sites
$ rmdir "yo-2"
rmdir: `yo-2': Directory not empty
I cant seem to get rmdir to work in git bash. Its not in a git repo and I've tried the above. Mkdir works as expected, why doesnt this?
rmdir will not work if directory is empty
Try
rm -rf yo-2
git-bash is a Linux like shell
If you are trying to remove an entire directory regardless of contents, you could use:
rm <dirname> -rf
just use the command below:
rm -rfv mydirectory
After trying out a couple of other commands, this worked for me:
rm dirname -rf
A bit late, but I believe it still can help someone with performance problems on Windows systems. It is REALLY FAST to delete on Windows using git bash comparing with just the ordinary rm -rf. The trick here is to move the file/directory to another random name in a temporary directory at the same drive (on Windows) or at the same partition (on *nix systems) and invoke the rm -rf command in background mode. At least you don't need to wait for a blocking IO task and OS will perform the deletion as soon it gets idle.
Depending on the system you are using you may need to install the realpath program (ie macOS). Another alternative is to write a bash portable function like in this post: bash/fish command to print absolute path to a file.
fast_rm() {
path=$(realpath $1) # getting the absolute path
echo $path
if [ -e $path ]; then
export TMPDIR="$(dirname $(mktemp -u))"
kernel=$(uname | awk '{print tolower($0)}')
# if windows, make sure to use the same drive
if [[ "${kernel}" == "mingw"* ]]; then # git bash
export TMPDIR=$(echo "${path}" | awk '{ print substr($0, 1, 2)"/temp"}')
if [ ! -e $TMPDIR ]; then mkdir -p $TMPDIR; fi
fi
if [ "${kernel}" == "darwin" ]; then MD5=md5; else MD5=md5sum; fi
rnd=$(echo $RANDOM | $MD5 | awk '{print $0}')
to_remove="${TMPDIR}/$(basename ${path})-${rnd}"
mv "${path}" "${to_remove}"
nohup rm -rf "${to_remove}" > /dev/null 2>&1 &
fi
}
# invoking the function
directory_or_file=./vo-2
fast_delete $directory_or_file
I have faced same issue. this is worked for me
rimraf is a Node.js package, which is the UNIX command rm -rf for node, so you will need to install Node.js which includes npm. Then you can run:
npm install -g rimraf
Then you can run rimraf from the command line.
rimraf directoryname
visit https://superuser.com/questions/78434/how-to-delete-directories-with-path-names-too-long-for-normal-delete
I found this solution because npm itself was causing this problem due to the way it nests dependencies.
Late reply, but for those who search a solution, for me the
rm <dirname> -rf
wasn't good, I always get the directory non-empty or path too long on node directories.
A really simple solution :
Move the directory you want to delete to the root of your disk (to shorten your path) and then you can delete it normally.
i am working on ubuntu server from past few months
and now suddenly ps, ifconfing commnad stop working with below error.
user1#Fb1:/usr/bin$ ps
-bash: /bin/ps: No such file or directory
any suggestions to get this command working back.
What's the output of which ps and ls /usr/bin -al (which are both in /bin also)? Does it work if you gain root privileges, either using sudo ifconfig or sudo su, then ifconfig?
This is possibly an issue with file permissions but it's hard to say without more information.
First use locate to find your ps or ifconfig program:
$ locate ps | grep bin
Also you may try whereis command:
$ whereis ps
If you don't find them, try to search as root user.
i have tried to put all the outputs of different commnads as below
root#Fb1:/usr/bin# whereis ps
ps: /bin/ps /usr/share/man/man1/ps.1.gz
root#Fb1:/usr/bin# ls -lsa ps
16 -rwxr-xr-x 1 root root 15859 2010-05-26 12:21 ps
Something wrong with your $PATH I suspect it doesn't have /sbin .. maybe new software overwrite your $PATH..
normal path should be include this (mebada is my user name)
mebada#T430:~$ echo $PATH
/home/mebada/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin