How to create undo checkout recursively in clearcase in context menu - clearcase

I'm trying to create undo checkout recursively..., context menu with arguments (I'm using clearmenuadmin.exe)
/c cleartool lsco -r -cvi -fmt "unco -rm %n\n"$dir|cleartool
but its not working.. any idea on how to do this..

Note: do put a space between the %n\n" and $dir.
In this case, the -fmt part will not ensure the execution, even piped to cleartool
Perhaps
/c cleartool lsco -r -cvi -fmt "cleartool unco -rm %n\n"$dir|cmd
would work, but I doubt it: the problem is visible when considering all the command launched when configure with the clearmenuadmin.exe:
cmd /c cleartool lsco -r -cvi -fmt "cleartool unco -rm %n\n"$dir|cmd
The |cmd or |ct would apply to the first cmd, not to the cleartool command.
I would rather use and external script (to wrap the unco command)
/c myUnco.cmd $dir
with myUnco.cmd stored in a directory referenced by your %PATH% environment variable, with;
cleartool lsco -r -cvi -fmt "cleartool unco -rm %n\n" %1|cleartool
Here (in the .cmd script) %1 represents the $dir passed through the clearcase contextual menu.

Related

How can I cd into directories in a for loop when the directories have spaces?

Here is a simple for loop where aaa.txt is a list of directories.
#!/bin/bash
for variable in $(cat aaa.txt)
do
cd $variable && mv *.avi /home/xxx/Downloads/Marple && rm -rf $variable
done
But each directory is something like:
Agatha Christies Marple 1x02 - The Murder At The Vicarage
The spaces prevent the $variable from working. I've tried "$variable" but that doesn't work.
So I changed aaa.txt to
Agatha\ Christies\ Marple\ 1x02\ -\ The\ Murder\ At\ The\ Vicarage
That didn't work either.
How can I 'cd' into directories with spaces?
You want:
#!/bin/bash
while IFS= read -r dir; do
cd "$dir" && mv *.avi /home/xxx/Downloads/Marple && rm -rf "$variable"
done < aaa.txt
to prevent work splitting.
Check How can I read a file line-by-line

Bash script to iterate over directories and create subdirectory

I have the following code which creates an array and iterate over a directory and create a subdirectory under each of the element of an array.
#!/bin/bash
cd /var/www
dirs=$(find * -maxdepth 0 -type d)
for dir in "${dirs[#]}"; do
echo $dir
mkdir $dir/backups
done
While it echo's all the directories, it creates a directory only on the last element of the array. What can be the issue?
If you are on bash 4.4 particularly , you can use the readarray feature like bellow. Also using -maxdepth 0 seems not a good option - you probably need to use -maxdepth 1.
#!/bin/bash
cd /var/www
readarray -t -d'' dirs < <$(find . -maxdepth 1 -type d -print0)
for dir in "${dirs[#]}"; do
echo $dir
mkdir $dir/backups
done
But in case you can do the whole thing just with find and mkdir -v (verbose):
$ find . -maxdepth 1 -type d -name 'a*'
./appsfiles
$ find . -maxdepth 1 -type d -name 'a*' -exec mkdir -v {}/backup \;
mkdir: created directory './appsfiles/backup'
Using mkdir -v you get verbose messages from mkdir and you can skip the echo.
If you need the echo anyway, you can do it like:
$ find . -maxdepth 1 -type d -name 'a*' -exec bash -c 'echo $0 && mkdir -v $0/backup' {} \;
./appsfiles
mkdir: created directory './appsfiles/backup'
The issue the array initialization - change it to:
dirs=($(find * -maxdepth 0 -type d))
However, the above statement can be problematic if you have directories that have white spaces in them.
You can use a simple glob instead - it handles white spaces too:
cd /var/www
dirs=(*/)
for dir in "${dirs[#]}"; do
: your code
done

Copying files from Snapshot View

I am trying to copy files from snapshot view using the cmd code
cleartool find . -all -type f -version "lbtype(%LABEL%)" -exec "cmd /c echo f | xcopy /f /y \"%%CLEARCASE_XPN%%\" \"%STAGING_FOLDER%\%LABEL%\%%CLEARCASE_PN%%\""
But while copying files I need to copy only after a certain folder from snapshot view like
eg: DEV_VOB\LOG##\main\DEV1_Integration\2\ I want to copy files only after this.
I did try /EXCLUDE in xcopy but not working.
Need help with this.
The easier way is to include a grep before the xcopy:
cleartool find ... | grep "DEV_VOB\LOG##\main\DEV1_Integration\2\" && xcopy ...
If the grep succeeds, then the second part of the command after the && will be executed.
If the grep fails, then the second part (xcopy) won't be executed.
You have various sources for a grep on windows, like gnuwin32.sourceforge.net.
Truthfully, this won't work. You're trying to use a version extended path in a snapshot view. Those will not work.
There is a command that allows you to extract arbitrary versions from the repository and place them in another arbitrary location: cleartool get
Something along these lines may work:
cleartool find ... -exec "cleartool get -to \"%STAGING_FOLDER%\%LABEL%\%%CLEARCASE_PN%%\" \"%CLEARCASE_XPN%\""

How do I control evaluation order?

For example, cd (echo ..) works in powershell, but how do I get it working in batch (it evaluates the echo first, and so the command is effectively cd ..)? mycommand.exe (ls -fi *.hs -exclude \"#*\" -name -r) is what I'm actually trying to convert (it sends a, completed, filtered file listing to mycommand).
setlocal enabledelayedexpansion
set LIST=
for /r %%F in (*.hs) do (
set "FN=%%F"
if not "!FN:~0,1!"=="#" set LIST=!LIST! "%%F"
)
mycommand.exe !LIST!
would be a rough translation.
add the $ symbol to evaluate the commands in the parens first:
mycommand.exe $(ls -fi *.hs -exclude \"#*\" -name -r)
or
ls -fi *.hs -exclude \"#*\" -name -r | mycommand.exe
If you want to execute the command for each item returned from your ls, you can:
ls -fi *.hs -exclude \"#*\" -name -r | %{mycommand.exe $_ }

Delete some files using batch files

I must create batch file to delete files of a directory which names first symbols are "a". How can I do it?
If you're using Windows try this (assuming *full_path* is directory you want to delete in):
#echo off
DEL /Q full_path\a*.*
or if you want to delete files from that dir and in its subdir, try this:
#echo ff
DEL /Q /S full_path\a*.*
If you're using Linux (or similar), try this:
rm -f full_path/a*
or
rm -rf full_path/a*
If you are using something like Linux or OSX or Cygwin try
find . -name "a*" -delete
If you want to remove whole directories
find . -name "a*" | xargs -n 5 rm -r

Resources